sql表格模型获取记录内容

介绍 (Introduction)

A few weeks back I had been working on an interesting proof of concept for a client within the food / grocery industry. The objectives were to be able to provide the client with information on sales patterns, seasonal trends and location profitability. The client was an accountant and was therefore comfortable utilizing spreadsheets. This said, I felt that this was a super opportunity to build our proof of concept utilizing a SQL Server Tabular Solution and by exploiting the capabilities of Excel and Power Reporting for the front end.

几周前,我一直在为食品/杂货行业的客户提供有趣的概念证明。 目标是能够向客户提供有关销售模式,季节性趋势和地区盈利能力的信息。 客户是会计师,因此可以轻松使用电子表格。 这就是说,我觉得这是利用SQL Server表格解决方案并通过利用Excel和Power Reporting的前端功能来建立概念验证的绝佳机会。

In today’s “fire side chat” we shall be examining how this proof of concept was created and we shall get a flavour of the report types that may be generated, simply by utilizing Excel.

在今天的“旁白”中,我们将研究如何创建此概念证明,并且将简单地通过使用Excel来了解可能生成的报告类型。

In the second and final part of this article, we shall be examining the power of utilizing SQL Server Reporting Services 2016 to generate user reports.

在本文的第二部分也是最后一部分,我们将研究利用SQL Server Reporting Services 2016生成用户报告的功能。

However, before getting carried away with Reporting Services, let us look at the task at hand, that being to work with the tabular model and Excel Power Reporting.

但是,在不使用Reporting Services之前,让我们看一下手头的任务,即与表格模型和Excel Power Reporting一起使用。

Thus, let’s get started.

因此,让我们开始吧。

入门 (Getting Started)

Our journey begins with the raw data. Opening SQL Server Management Studio 2016, we locate a database which I have called SQLSaturday554. In the screenshot below, the reader will note that we have the beer sales from major South Africa cities for several years.

我们的旅程始于原始数据。 打开SQL Server Management Studio 2016,我们找到一个名为SQLSaturday554的数据库。 在下面的屏幕截图中,读者会注意到,几年来我们在南非主要城市都有啤酒销售。

We also have customer data within our “Customer” table (see below).

我们的“客户”表中也有客户数据(见下文)。

Last but not least, we have a “year month calendar table” (to add a time dimension) to our exercise (see below).

最后但并非最不重要的一点是,我们在练习中有一个“年月日历表”(添加时间维度)(请参见下文)。

For our exercise, we shall be working with these three tables.

对于我们的练习,我们将使用这三个表。

创建表格模型 (Creating our tabular model)

Should you not have a tabular instance installed upon your work server, you may want to install one from the media supplied from Microsoft. One merely adds another instance and select ONLY the Analysis Services option and then the “Tabular” option. The install is fairly quick.

如果您没有在工作服务器上安装表格形式的实例,则可能要从Microsoft提供的媒体中安装一个表格形式的实例。 一个人仅添加另一个实例,然后仅选择Analysis Services选项,然后选择“ Tabular”选项。 安装相当快。

Should you be unfamiliar with the Tabular Model itself, fear not as we shall be working our way through the whole process, step by step.

如果您不熟悉表格模型本身,请不要担心,因为我们将逐步逐步完成整个过程。

From this point on I shall assume that we all have a tabular instance installed upon our work servers.

从这一点开始,我将假定我们所有人都在工作服务器上安装了表格实例。

Opening Visual Studio 2015 or SQL Server Data Tools (2010 and above) we create a new project by selecting “New Project” under the Start banner as shown below.

打开Visual Studio 2015或SQL Server数据工具(2010及更高版本),我们通过在“开始”横幅下选择“新建项目”来创建一个新项目,如下所示。

The “Project Type” menu is brought up (see below).

出现“项目类型”菜单(请参见下文)。

We select an “Analysis Services Tabular Project” project (as shown above) and give our project an appropriate name. We click “OK” to create our project.

我们选择一个“ Analysis Services表格项目”项目(如上所示),并给我们的项目起一个适当的名称。 我们单击“确定”创建我们的项目。

The “Tabular Model Designer” now appears (see below).

现在将出现“表格模型设计器”(见下文)。

What the project wishes to know is to which TABULAR server and workspace we wish to deploy our model. We must remember that whilst our source data originates from standard relational database tables (for our current exercise), the project itself and the reporting will be based off data within Analysis Services.

项目希望知道的是我们希望将模型部署到哪个TABULAR服务器和工作空间。 我们必须记住,尽管我们的源数据来自标准关系数据库表(对于我们当前的工作),但是项目本身和报告将基于Analysis Services中的数据。

We set the “Workspace Server” and test the connection as shown above. We click OK to create the model and we are then brought to our design and work surface (see below).

我们设置“工作区服务器”并测试连接,如上所述。 我们单击“确定”创建模型,然后将其带入设计和工作界面(见下文)。

We now double click on the “Model.bim” icon, shown in the screen shot below.

现在,我们双击“ Model.bim”图标,如下图所示。

The model designer opens (see below).

将打开模型设计器(请参见下文)。

将数据添加到我们的模型 (Adding data to our model)

Clicking upon the “Model” tab on the menu ribbon (see below) we select “Import from Data Source”.

单击菜单功能区上的“模型”选项卡(见下文),我们选择“从数据源导入”。

The “Table Import Wizard” appears (see below).

出现“表导入向导”(见下文)。

We select “Microsoft SQL Server” as shown above because our source data is from the relational database tables that we saw above. We then click “Next”.

我们如上所述选择“ Microsoft SQL Server”,因为我们的源数据来自我们在上面看到的关系数据库表。 然后,我们单击“下一步”。

We now select our “source” database server, our database and test our connection (see above). Once again, we click “Next”.

现在,我们选择“源”数据库服务器,数据库并测试我们的连接(请参见上文)。 再次单击“下一步”。

We must now set out “Impersonation Information” (see the screenshot above). In our case I have chosen to utilize a specific Windows user name and password. Once set, we click “Next”.

现在,我们必须列出“假冒信息”(请参见上面的屏幕截图)。 在我们的情况下,我选择使用特定的Windows用户名和密码。 设置完成后,我们单击“下一步”。

The system now wants us to select the relational tables that we wish to import into our model. We select the “Select from a list of tables and views to choose the data to import” option (see above). We then click “Next”.

系统现在希望我们选择要导入到模型中的关系表。 我们选择“从表和视图列表中选择以选择要导入的数据”选项(见上文)。 然后,我们单击“下一步”。

We select the “beersales554” (Our sales figures), “Customer” (our list of clients), and “datee” (our time dimension) tables (see above) and then click “Finish”. The project will then begin the import into our model (see below).

我们选择“ beersales554”(我们的销售数据),“客户”(我们的客户列表)和“ datee”(我们的时间维度)表(见上文),然后单击“完成”。 然后,该项目将开始导入到我们的模型中(见下文)。

Should our load was successful, then we receive the message shown above. We now click “Close”.

如果加载成功,我们将收到上面显示的消息。 现在,我们单击“关闭”。

Our data will now appear within our design window (see the screenshot above). WOW, it looks like a spreadsheet. Those finance folks are going to love this!

现在,我们的数据将出现在我们的设计窗口中(请参见上面的屏幕截图)。 哇,看起来像电子表格。 那些财务人员会喜欢这个!

让乐趣开始!! (Let the fun begin!!)

The astute reader will note that in addition to the “Province”, “City” and “CustomerNo”, we also have a “yearmth” field and a field containing the Rand value of beer sales.

精明的读者会注意到,除了“省”,“城市”和“客户编号”之外,我们还有一个“年份”字段和一个包含兰德啤酒销售额的字段。

This breakdown is on a monthly basis and oft times folks wish to see results by quarter. GOTCHA!!!!

这种细分是每月一次,而且人们经常希望按季度查看结果。 GOTCHA !!!

The one thing that we must remember is that now that we are working with the tabular model, calculations or defined fields cannot be created utilizing standard T-SQL. We must utilize DAX (data analysis expressions).

我们必须记住的一件事是,由于我们正在使用表格模型,因此无法使用标准T-SQL创建计算或定义的字段。 我们必须利用DAX(数据分析表达式)。

We select “Add Columns” (as shown above) and add our DAX expression

我们选择“添加列”(如上所示)并添加DAX表达式


=IF(RIGHT([yearMth],2)>="01" &&
RIGHT([yearMth],2)<="03",1,IF(RIGHT([yearMth],2)>="04" &&
RIGHT([yearMth],2)<="06",2,IF(RIGHT([yearMth],2)>="07" &&
RIGHT([yearMth],2)<="09",3,4)))

to the “function box” below the menu ribbon (see above).

进入菜单功能区下方的“功能框”(请参见上文)。

The “Quarter” has now been created (see below).

现在已经创建了“ Quarter”(请参见下文)。

Once again, the eagle – eyed reader will question the financial year calendar. Fear not, the same DAX expression may be used for a fiscal year starting July 1 and ending June 30th. Such is the beauty of the DAX language.

目光敏锐的读者将再次质疑财政年度日历。 不用担心,从7月1日到6月30 结束的会计年度可以使用相同的DAX表达式。 这就是DAX语言的美。

We now rename the column to “Quarter” (See below).

现在,我们将该列重命名为“ Quarter”(如下所示)。

汇总我们的“金额” (Aggregating our “Amounts”)

As “champions of reporting”, we all know that the decision makers will want to view reports which have aggregated results, by region and by time. This said we now aggregate our “Amount” field so that when we report from our tabular “cube”, the results will be aggregated at the appropriate level.

作为“报告冠军”,我们都知道决策者将希望按地区和时间查看汇总结果的报告。 也就是说,我们现在汇总“金额”字段,以便当我们从表格“多维数据集”报告时,结果将在适当的级别汇总。

We place our cursor in any cell below our data display (see the blue highlighted cell in screen shot below). It should be understood that “any cell below the data is adequate”.

我们将光标放置在数据显示下方的任何单元格中(请参见下面的屏幕截图中蓝色突出显示的单元格)。 应该理解,“数据下方的任何单元格都足够”。

We now create the DAX formula to aggregate the data.

现在,我们创建DAX公式以汇总数据。


GrandTotal := Sum([Amount])

The DAX formula is created in the same function box that we utilized for the “Quarter”, and a grand total will display in the blue cell (shown below).

DAX公式是在与“季度”相同的功能框中创建的,总计将显示在蓝色单元格中(如下所示)。

It should be remembered that at this point in time that the result is meaningless as we have not linked “Amount” to our date and customer dimensions

sql表格模型获取记录内容_SQL Server和BI –如何使用Excel记录表格模型相关推荐

  1. sql表格模型获取记录内容_SQL Server和BI –如何使用Reporting Services 2016记录表格模型

    sql表格模型获取记录内容 介绍 (Introduction) A few weeks back I had been working on an interesting proof of conce ...

  2. server sql top速度变慢解决方案_SQL Server的性能调优:解决查询速度慢的五种方法-数据库...

    编辑推荐: 本文主要通过一下几个方面介绍:使用SQL DMV查找慢速查询.通过APM解决方案查询报告.SQL Server扩展事件.SQL Azure查询性能洞察等相关内容. 本文来自博客园,由火龙果 ...

  3. server sql top速度变慢解决方案_SQL Server查询优化方法(查询速度慢的原因很多,常见如下几种) ....

    今天看到一位博友的文章,觉得不错,转载一下,希望对大家有帮助,更多文章,请访问:http://blog.haoitsoft.com 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺 ...

  4. server sql top速度变慢解决方案_SQL Server查询优化方法(查询速度慢的原因很多,常见如下几种)...

    1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列导致查询不优化. 4.内存不足 5.网络速度慢 6.查询出的数据量过大 ...

  5. sql简单带索引的语句_SQL Server 2017:栏目索引和简单计划

    sql简单带索引的语句 Some time ago, SQL Server 2017 was released and issued as CTP. The most exciting release ...

  6. server sql top速度变慢解决方案_SQL Server:执行计划教会我如何创建索引?(解决SQL加了TOP之后变很慢的问题)...

    今天,在测试一个SQL语句,是EF自动生成的,发现很奇怪的事情:SQL 加了TOP (20)之后,速度慢了很多,变成36秒,如果没有TOP (20),只需要2秒,查看执行计划,发现变成了全表扫描,但是 ...

  7. server sql top速度变慢解决方案_SQL Server查询速度慢原因及优化方法

    SQL Server数据库查询速度慢的原因有很多,常见的有以下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列 ...

  8. server sql top速度变慢解决方案_SQL Server数据库查询速度慢的原因和解决方法

    SQL Server数据库查询速度慢的原因有很多,常见的有以下几种: 1.没有索引或者没有用到索引(这是查询慢最常见的问题,是程序设计的缺陷) 2.I/O吞吐量小,形成了瓶颈效应. 3.没有创建计算列 ...

  9. sql 如何设置行级锁_SQL Server 2016中的行级安全性

    sql 如何设置行级锁 With the release of SQL Server 2016 comes many great new features. One of these is the i ...

最新文章

  1. 51CTO学院薛大龙软考班,再努力一点点就能成功了
  2. OpenCv 005---图像像素的算术操作
  3. Android MagicIndicator系列之一 —— 使用MagicIndicator打造千变万化的ViewPager指示器...
  4. 【floyd存字典序路径】【HDU1385】【Minimum Transport Cost】
  5. KDD 18 AAAI 19 | 异构信息网络表示学习论文解读
  6. OpenCASCADE:构建线程
  7. Python基础之:struct和格式化字符
  8. C++学习笔记章节中 面向对象详解
  9. 卡扇区数据教程_分享一款硬盘分区和数据恢复软件
  10. 程序员or需求工程师,谁决定软件的最高水平?
  11. python监控桌面捕捉_想要远程获取对方的桌面?Python教你一招搞定!
  12. 转载: .net程序员偏向XML开发的面试题
  13. VLC设置串流的TTL值
  14. python如何调用dll库中的函数_Python调用DLL动态库函数读写CPU卡
  15. Docker安装以及docker run hello-world 不能下载镜像报错
  16. 江南大学计算机考研资料汇总
  17. JefferyZhao教导我们...
  18. HTML5 之 Img 标签
  19. 服务器guid怎么装系统,GUID分区模式,UEFI+PGT磁盘模式安装Ghost系统详解
  20. 【图的表示】:如何存储微博、微信等社交网络中的好友关系?

热门文章

  1. python二维分布图怎么画_python3怎样画二维点图
  2. unity 主线程调用_Kafka的Producer的调用序列图
  3. 一文带你了解Java反射机制
  4. C语言学习系列(六)基本语法
  5. vmware vcenter orchestrator configuration提示“用户名密码错误或登录失败超过次数被锁定”...
  6. SQL Server时间粒度系列----第4节季、年时间粒度详解
  7. javaScript内置对象简介
  8. 【零基础学Java】—Java 日期时间(三十一)
  9. 工资10000元,应该交多少税?
  10. 家里的所有网线都集中到了弱电箱怎么组网?