mvc中嵌入ssrs报表

Ever since the early days of my career, SQL Server Reporting Services (SSRS) has been one of my preferred data visualization tools simply because end users and developers alike use it for free. Although a majority of my SSRS solutions have been based off a relational dataset that uses Transact SQL (T-SQL), I have also produced several reports that used Multidimensional Expressions (MDX) to connect and retrieve data from SQL Server Analysis Services (SSAS) multidimensional OLAP cube. Recently, I found myself having to refactor some of these SSAS based SSRS reports, particularly converting a single value SSAS-populated parameter into a multi-value parameter. In this article, I explore how you can go about making these changes using SSRS query designer’s design and query modes.

从我职业生涯的早期开始,SQL Server Reporting Services(SSRS)就一直是我首选的数据可视化工具之一,因为最终用户和开发人员都可以免费使用它。 尽管我的大多数SSRS解决方案都基于使用Transact SQL(T-SQL)的关系数据集,但我也产生了一些使用多维表达式(MDX)连接并从SQL Server Analysis Services(SSAS)检索数据的报告。多维OLAP多维数据集。 最近,我发现自己不得不重构一些基于SSAS的SSRS报告,尤其是将单值SSAS填充的参数转换为多值参数。 在本文中,我将探讨如何使用SSRS查询设计器的设计和查询模式进行这些更改。

在设计模式下使用查询参数 (Working with query parameters in design mode)

Just like using a relational database to define your report dataset requires an understanding of T-SQL, referencing multidimensional OLAP cube data requires a basic understanding of MDX. However, you can circumvent the MDX learning process by using a GUI – Graphical User Interface – to build and prepare your report dataset. In the context of SSRS, the GUI includes a dataset query designer’s design mode. It involves navigating to a new dataset, choosing your SSAS data source and then clicking and dragging the measures and dimensions you want to report on. In my FruitSales demo cube shown in Figure 1, I have chosen Count as my measure and Fruit and MOP (method of payment), as my dimensions.

就像使用关系数据库来定义报告数据集一样,您需要了解T-SQL,引用多维OLAP多维数据集数据也需要对MDX有基本的了解。 但是,您可以使用GUI(图形用户界面)来构建和准备报告数据集,从而规避MDX学习过程。 在SSRS的上下文中,GUI包括数据集查询设计者的设计模式。 它涉及导航到新的数据集,选择SSAS数据源,然后单击并拖动要报告的度量和维。 在图1所示的FruitSales演示多维数据集中,我选择了Count作为度量值,并选择了FruitMOP (付款方式)作为维度。

Adding parameters to our dataset using the designer is also effortless. All you need to do is navigate to the top right filter section of the designer, specify the dimension you want to filter on and check the box underneath the Parameters field. In this example, I have chosen to use MOP as a filter with a default value of CASH. The rest of the dataset looks as shown in Figure 2.

使用设计器向我们的数据集添加参数也是轻松的。 您需要做的只是导航到设计器的右上方过滤器部分,指定要过滤的尺寸,然后选中“参数”字段下面的框。 在此示例中,我选择将MOP用作默认值为CASH的过滤器。 数据集的其余部分如图2所示。

Once you close the query designer, you get to see an MDX script that was generated based on the selections you made. The script generated based on Figure 2 is shown in Script 1.

关闭查询设计器后,您将看到基于所做选择生成的MDX脚本。 基于图2生成的脚本显示在脚本1中


SELECT non empty { [Measures].[Count] }
ON columns, non empty { ([DimFruits].[Fruit].[Fruit].ALLMEMBERS * [DimFruits].[MOP].[MOP].ALLMEMBERS ) } dimension properties member_caption, member_unique_name
ON rows
FROM   ( SELECT ( strtoset(@DimFruitsMOP, constrained) ) ON columns FROM   [FruitsSales]) cell properties value, back_color, fore_color, formatted_value, format_string, font_name, font_size, font_flags

Having successfully set up a SSAS dataset using GUI, we can proceed to develop a report and Figure 3 shows us a preview of the newly developed report.

使用GUI成功设置了SSAS数据集之后,我们可以继续开发报告, 图3为我们展示了新开发的报告的预览。

Although the GUI makes it easy for novice developers to set up a parameterized SSRS report that is based off a multidimensional cube, there are several drawbacks to this approach:

尽管GUI使新手开发人员可以轻松地基于多维多维数据集来设置参数化的SSRS报告,但是此方法有一些缺点:

  1. The auto-generated script (in Script 1) includes unnecessary formatting information (i.e. BACK_COLOR, FORE_COLOR) that is embedded in the query – which makes the script untidy and not easy to read.

    自动生成的脚本(在脚本1中)包括嵌入在查询中的不必要的格式信息(即BACK_COLOR,FORE_COLOR ),这使脚本不整洁且不易于阅读。

  2. The dataset parameter name (and subsequently, report parameter name) is not business friendly as it is derived from a concatenation of dimension name (DimFruits) and dimension member (MOP).

    数据集参数名称(以及随后的报告参数名称)不是业务友好的,因为它是由维名称( DimFruits )和维成员( MOP )的串联而派生的。

  3. Another issue relating to parameter is that parameter values contains an MDX notation (i.e. [Dimension].[Member].&[Value]) that is not business friendly.

    与参数有关的另一个问题是,参数值包含不友好的MDX表示法(即[Dimension]。[Member]。&[Value] )。

在查询模式下使用查询参数 (Working with query parameters in query mode)

The drawbacks mentioned in the preceding section can be resolved by writing your own MDX script which gives you control of the dataset and ultimately the report. To edit MDX script we will switch from design mode into query mode.

上一节中提到的缺点可以通过编写自己的MDX脚本来解决,该脚本使您可以控制数据集并最终控制报表。 要编辑MDX脚本,我们将从设计模式切换到查询模式。

  1. Single-value parameters using STRTOMEMBER

    使用STRTOMEMBER的单值参数

    MDX has several built-in functions that can be useful when it comes to parameterising query datasets. One of those functions is the STRTOMEMBER which returns a member specification. Script 2 shows a refactored version of Script 1 that makes use of the STRTOMEMBER function.

    MDX具有多个内置函数,在参数化查询数据集时非常有用。 这些函数之一是STRTOMEMBER ,它返回成员规范。 脚本2显示了使用STRTOMEMBER函数的脚本1的重构版本。

    
    SELECT NON EMPTY { [Measures].[Count] } ON COLUMNS,
    NON EMPTY
    {( [DimFruits].[Fruit].[Fruit].AllMembers ) *{ StrToMember ( @MOP ) }
    } ON ROWS
    FROM [FruitsSales]

    Script 2: MDX Script Using STRTOMEMBER

    脚本2:使用STRTOMEMBER的 MDX脚本

    Script 2 makes references to a parameter called @MOP. Unlike in design view, this parameter will not be automatically added into the dataset instead we have to manually add it. Figure 4 shows the definition of the @MOP parameter with a default value of CASH.

    脚本2引用了一个名为@MOP的参数。 与设计视图不同,此参数不会自动添加到数据集中,而是我们必须手动添加它。 图4显示了@MOP参数的定义,其默认值为CASH

    Figure 4
    图4

    Following the changes made to our shared dataset, a preview of our demo report is shown in Figure 5. In terms of the layout, not much has changed since we updated the script to use STRTOMEMBER except for the parameter name which is no longer prefixed by a dimension name.

    更改共享数据集后,演示报告的预览如图5所示。 在布局方面,自从我们更新脚本以使用STRTOMEMBER以来,除了参数名称不再以尺寸名称作为前缀之外,没有太大变化。

    Figure 5
    图5

    Evidently, we still have an issue of a predefined parameter value that contains MDX expression. We need to refactor this in such a way that it displays member value only (i.e. CASH, ELECTRONIC etc.). We can do this by having the MOP parameter populated by a separate lookup dataset. Script 3 shows an MDX script for a dataset that will be used to populate the MOP parameter.

    显然,仍然存在包含MDX表达式的预定义参数值的问题。 我们需要重构它,使其仅显示成员值(即现金,电子等)。 我们可以通过由单独的查找数据集填充MOP参数来实现。 脚本3显示了将用于填充MOP参数的数据集的MDX脚本。

    
    WITH MEMBER [Measures].[Label] AS [DimFruits].[MOP].currentmember.member_caption MEMBER [Measures].[Value] AS [DimFruits].[MOP].currentmember.uniquename
    SELECT { [Measures].[Label], [Measures].[Value] } ON COLUMNS, [DimFruits].[MOP].allmembers ON ROWS
    FROM [FruitsSales] 
    Script 3: MOP Lookup MDX Query
    脚本3:MOP查找MDX查询

    The updated report which references the newly added dataset is shown in Figure 6. As it can be seen, this view of the report allows end users to choose the method of payment without having to specify an MDX expression.

    引用了新添加的数据集的更新报告如图6所示。 可以看出,该报告视图允许最终用户选择付款方式,而无需指定MDX表达式。

    Figure 6
    图6
  2. Multi-value parameters using STRTOSET

    使用STRTOSET的多值参数

    STRTOMEMBER function resolved several limitations of an MDX script generated via design mode. Unfortunately, STRTOMEMBER function has its own limitation which is – it doesn’t allow us to choose multiple parameter values. For instance, if we attempt to choose multiple MOPs, we receive an error as shown in Figure 7.

    STRTOMEMBER函数解决了通过设计模式生成的MDX脚本的一些限制。 不幸的是, STRTOMEMBER函数有其自身的局限性,即它不允许我们选择多个参数值。 例如,如果我们尝试选择多个MOP,则会收到如图7所示的错误。

    Figure 7: STRTOMEMBER function expects a member expression error
    图7:STRTOMEMBER函数期望成员表达式错误

    In order to address this limitation of STRTOMEMBER function, we make use of another MDX built-in function –STRTOSET. The revised script that uses STRTOSET function is shown in Script 4.

    为了解决STRTOMEMBER函数的这一限制,我们使用了另一个MDX内置函数STRTOSET脚本4中显示了使用STRTOSET函数的修订脚本。

    
    SELECT non empty { [Measures].[Count] }
    ON columns, non empty { ([DimFruits].[Fruit].[Fruit].ALLMEMBERS) * {strtoset(@MOP)} }
    ON rows
    FROM   [FruitsSales]
    STRTOMEMBERSTRTOMEMBER的 MDX脚本

    The MOP parameter was also modified to include multi-values as shown in Figure 8.

    如图8所示,还修改了MOP参数以包含多值。

    Figure 8
    图8

    A preview of the updated report that uses the script that references STRTOSET is shown in Figure 9. As it can be seen, it is now possible to choose multiple methods of payments without breaking report execution.

    图9显示了使用引用STRTOSET的脚本的更新报告的预览。 可以看出,现在可以选择多种付款方式而不会影响报告的执行。

    Figure 9
    图9

结论 (Conclusion)

In this article, we have demonstrated that unlike using T-SQL, populating an SSRS dataset using a multidimensional OLAP cube requires, at the very least, a basic understanding of MDX. We also demonstrated that out of the two modes, design and query mode, the query mode gives you more control of the dataset properties and handling of query parameters using the STRTOMEMBER and STRTOSET built-in MDX functions.

在本文中,我们证明了与使用T-SQL不同,使用多维OLAP多维数据集填充SSRS数据集至少需要对MDX有基本的了解。 我们还演示了在设计和查询两种模式中,查询模式使用STRTOMEMBERSTRTOSET内置MDX函数使您可以更好地控制数据集属性和查询参数的处理。

参考资料 (References)

  • StrToMember (MDX)StrToMember(MDX)
  • StrToSet (MDX)StrToSet(MDX)
  • Multidimensional Expressions (MDX)多维表达式(MDX)

翻译自: https://www.sqlshack.com/filter-multidimensional-olap-cubes-ssrs-reports/

mvc中嵌入ssrs报表

mvc中嵌入ssrs报表_如何在SSRS报表中过滤多维OLAP多维数据集相关推荐

  1. 怎样在表格中选出同一类_如何在excel表格中同一个框选择下一行 - 卡饭网

    在excel表格中怎样设置选择下拉列表? 在excel表格中怎样设置选择下拉列表? 在excel表格制作中,经常会遇到固定选项输入,例如性别( 男  女),婚否(是, 否),在制作考勤表的时候也可以利 ...

  2. 如何提取edit control中输入的数据_如何在Power Query中提取数据——列表篇(1)

    表名为列表,第一步骤名称为源 (一)从头开始提取 1. 获取列表第一个 List.First(list as list, optionaldefaultValue as any)as any 返回列表 ...

  3. 如何在代码中让按钮高亮_如何在C代码中插入移位寄存器

    上期内容:AI Engine到底是什么? 众所周知,标准C或C++代码是没有HDL代码的并行性和时序性的,那么如何在C代码中插入寄存器呢?Vivado HLS提供了IP库,这些IP库使得HLS可直接从 ...

  4. ux设计中的各种地图_如何在UX设计中使用颜色

    ux设计中的各种地图 Color is the mother tongue of the subconscious. 颜色是潜意识的母语. - Carl Jung -荣格 Color has more ...

  5. excel中 复制工作表_如何在Excel 2013中轻松移动或复制工作表

    excel中 复制工作表 There may be times when you want to create a new Excel worksheet based on an existing w ...

  6. java实现可视化报表_如何在Power BI中记录报表可视化?

    我一直在使用Dax来帮助我记录我的Power BI文件 . 使用Dax查询我已经能够记录文件中存在的所有字段,包括计算和测量字段 . 在我的文档处理过程中,我也希望找到一种在报表上记录可视化的方法 - ...

  7. 如何在cad中导入谷歌地图_如何在Google地图中设置出发和到达时间

    如何在cad中导入谷歌地图 Unless you work from home, Google Maps is fantastic at knowing where you need to be, a ...

  8. 如何在cad中导入谷歌地图_如何在Google地图中避开收费公路

    如何在cad中导入谷歌地图 No one likes to pay to be able to drive on a specific road, especially if you're just ...

  9. 怎样在dos窗口中启动mysql服务器_如何在dos命令中启动mysql或sql server 服务器的一些操作...

    ========================dos命令启动mysql或者sql srever 的步骤================= 一.dos命令启动mysql 1.进入dos命令窗口 2.启 ...

最新文章

  1. 摄像头和激光雷达都被蒙蔽?UCI首次提出针对自动驾驶多传感器融合感知的攻击...
  2. SuperVoxel:PCL中点云的超体素
  3. 收藏——CodeProject - 使用特性(attributes)和激活机制来实现工厂模式
  4. 【收藏】keepalived nginx服务检测脚本
  5. VTK:Medical之TissueLens
  6. Linux截取文件名的后几位,Linux字符串截取和处理命令 cut、printf、awk、sed、sort、wc...
  7. html为何转换为json,将HTML元素的“样式”属性转换为JSON
  8. 基于JAVA+SpringBoot+Mybatis+MYSQL的中小型超市进销存管理系统
  9. 前端-requests-flask对应关系 restful
  10. freeCodeCamp:Title Case a Sentence
  11. 小程序ASC解密(java)
  12. MySQL二进制日志(binlog)总结
  13. java前后端开发文档汇总
  14. 如何批量将class文件反编译为java文件?
  15. 第10章 项目沟通管理
  16. VS2019删除空白行
  17. java控制小数位数_java中怎么控制double的小数位数?
  18. 从机械硬盘和固态硬盘的结构来看IO
  19. “D语言风采不再”的说法言过其实
  20. Unicode双向算法详解(bidi算法)(三)

热门文章

  1. jq post 表单提交文件_Power Query 中使用POST方法进行网络抓取的尝试
  2. Joseph_Circle(约瑟夫环)
  3. mysql安装设置mysql字符集utf8及修改密码
  4. Java回文数的判断与生成
  5. JPA学习笔记二——Hello World
  6. jquery--动态篇
  7. HDU - 1281 棋盘游戏
  8. Deep Residual Network
  9. Window下JDK、Tomcat、eclipse安装与配置
  10. 上海雄联机械配件有限公司