[{"id":"bcb0874d-299b-448e-9552-9e9b25ef80dd","tags":[{"product":null,"links":null,"id":"ba7e818e-4f6b-4211-b1ac-58e3bafcf439","name":"\u66F4\u65B0","color":"orange","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8ce3627e-9e58-471b-9133-4f135d191e7b","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"ae60ae59-34f5-4f32-a8eb-243ed1457543","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"3d4848c3-910f-4ffa-9153-60bb507334a9","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"133f4ca6-d951-4d65-a618-3dc6301266f7","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"de62ec1c-813e-40b1-8160-a4cd109afe64","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2426c71d-8332-4cbd-a436-1ec4f8666464","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2ce7b6b0-78aa-4e4b-bf8a-e4ba2f988298","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"4706db46-0811-4652-8f59-1e0a1da84758","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"8f1271bb-2cd9-4f39-9897-c15b239ee7ab","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"677e13a7-6f3e-449f-986c-2c3a26f8d54f","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"5e40f6dc-caec-49d7-a1d0-be65f06815ba","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"2457f0e0-9e71-4860-a87d-065e0fb84f84","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"d5c67fd0-1145-482c-9113-97b492c44c18","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"a609a8fa-ab91-4c1d-a1c3-d209d0463303","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]},{"id":"b4a9eb15-94e5-48df-b218-a24138f0cf9c","tags":[{"product":null,"links":null,"id":"adf72f47-7f61-4239-8392-b9bcc127fa80","name":"\u65B0\u589E","color":"green","productId":"0995490e-43fc-4d6e-bc8d-8e66f38b0c63"}]}]
        
(Showing Draft Content)

累计分析

需求描述

累计分析一般用来做累积的计算。

比如:

  • 从1月到12月,或者到现在的累计销售率分析。

  • 今年的销售完成率,也即全年的Sum(Cost)/Sum(Budget)。

  • 到目前为止的销售完成率,也即到现在为止的Sum(Cost)/Sum(Budget)。

在本例中,我们要累计的值为 Sum(SaleAmount),维度为年份。

在仪表板中实现

1. 添加图表,并绑定分类字段。

image2021-12-15_17-58-1.png


2. 在表 'FactResllerSales'上添加一个度量值。

image2021-12-16_9-40-49.png


3. 输入度量值的名称和分析表达式并保存。

表达式内容如下,有关表达式的解析请见本页下方内容。

CALCULATE(
            SUMW(
                SUMMARIZE(
                    CALCULATETABLE(
                        SELECTCOLUMNS(
                            FactResellerSales,
                            "FactResellerSales_OrderDate_Year",
                            Year(
                                'FactResellerSales'[OrderDate]
                            )
                        )
                    ),
                    [FactResellerSales_OrderDate_Year],
                    "FactResellerSales_SalesAmount_SUMX",
                    CALCULATE(
                        SUMX(
                            CALCULATETABLE(
                                ADDCOLUMNS(
                                    SELECTATTRIBUTES(
                                        FactResellerSales,
                                        'FactResellerSales'[SalesAmount]
                                    ),
                                    "FactResellerSales_OrderDate_Year",
                                    Year(
                                        'FactResellerSales'[OrderDate]
                                    )
                                )
                            ),
                            'FactResellerSales'[SalesAmount]
                        )
                    ),
                    "FactResellerSales_OrderDate_Year_Order_null",
                    CALCULATE(
                        ROWNUMBERW(
                            CALCULATETABLE(
                                DISTINCT(
                                    SELECTCOLUMNS(
                                        FactResellerSales,
                                        "FactResellerSales_OrderDate_Year",
                                        Year(
                                            'FactResellerSales'[OrderDate]
                                        )
                                    )
                                )
                            ),
                            OrderBy(
                                [FactResellerSales_OrderDate_Year]
                            )
                        )
                    )
                ),
                [FactResellerSales_SalesAmount_SUMX],
                OrderBy(
                    [FactResellerSales_OrderDate_Year_Order_null]
                )
            )
        )

image2021-12-16_9-42-49.png


4. 使用新建度量值绑定到数值区域绘制图形。

image2021-12-16_9-47-28.png

表达式解析

首先来看最外层的 CALCULATE函数。

image2021-12-16_9-51-45.png

第一个参数是必需的,过滤器是可选的。在这种情况下,我们可以删除 CALCULATE 函数。

其次,SUMW 函数语法如下:

SUMW(<table>,<expression> [,PARTITIONBY(<expression>[,[expression] [,...]])] [,ORDERBY(<expresion> [(ASC|DESC)] [,<expression> [(ASC|DESC)] [,...] ] )] [,(ROWS|RANGE)( ((UNBOUNDED|<Number>) (PRECEDING|FOLLOWING) | CURRENT ROW) [,((UNBOUNDED|<Number>) (PRECEDING|FOLLOWING) | CURRENT ROW)])])

在这种情况下,可选子句仅按 sub-function 排序。

image2021-12-16_9-55-41.png


1) 参数 <table>

第一个参数 <table> 是必需的。它可以是一个表或一个表函数,返回值是一个表。这个参数非常重要,必须包含维度(用于分组),值(需要在窗口函数中计算)的列。


当前情况下,表是一个函数。我们可以看到它包含按列分组(Year(OrderDate)),需要在窗口函数中计算的两个值(“FactResellerSales_SalesAmount_SUMX”,“FactResellerSales_orderDate_Year_Order_null”)。


结构如下:

image2021-12-16_10-9-48.png

可以看到我们使用了 Summarize 函数来生成表格。第一个参数也是一个表格(使用表格函数),第二个参数是维度(需要分组),第三个等等。

参数是名称和表达式。维度名称必须遵循规则:如果不需要提取日期时间,名称为“tableName_columnName”,如果需要提取日期时间,名称为“tableName_columnName_Type”,这里的类型可以是年,月,日,小时,分,秒。维度名称不区分大小写。

2) 参数<expression>

第二个参数 <expression> 是必需的。这里它可能是来自第一个参数 <table> 的“非限定”名称。

3)参数<OrderBy>clause

该参数是可选的。但是如果我们要计算累积值,就需要这个参数。这也是来自第一个参数 <table> 的“非限定”名称。