SUMMARIZE

返回一个摘要表,显示对一组函数的请求总数。

语法

SUMMARIZE (<table>, <groupBy_columnName>[, <groupBy_columnName>]…[, <name>, <expression>]…)

parameters

术语定义
返回数据表的任何 DAX 表达式。
groupBy_ColumnName(可选)要用于根据列中的值创建摘要组的现有列的限定名称。 此参数不能是表达式。
name为总计或汇总列指定的名称,用双引号引起来。
表达式返回单个标量值的任何 DAX 表达式,其中,表达式将被计算多次(针对每行/上下文)。

返回值

一个表,其中包含 groupBy_columnName 参数的选定列,以及名称参数设计的汇总列 。

备注

  • 为其定义名称的每个列都必须具有一个对应的表达式;否则,将返回错误。 第一个参数 name 定义结果中列的名称。 第二个参数 expression 定义为获取该列中每一行的值进行的计算。

  • groupBy_columnName 必须位于表中,或位于与表相关的表中 。

  • 每个名称都必须用双引号引起来。

  • 函数根据一个或多个 groupBy_columnName 列的值将一组选定的行归组为一组摘要行。 为每个组返回一行。

  • 在已计算的列或行级安全性 (RLS) 规则中使用时,不支持在 DirectQuery 模式下使用此函数。

示例

下面的示例返回按日历年和产品类别名称分组的经销商销售额的摘要,通过此结果表可以按年份和产品类别分析经销商销售额。

SUMMARIZE(ResellerSales_USD        , DateTime[CalendarYear]        , ProductCategory[ProductCategoryName]        , "Sales Amount (USD)", SUM(ResellerSales_USD[SalesAmount_USD])        , "Discount Amount (USD)", SUM(ResellerSales_USD[DiscountAmount])        )  

下表显示了数据预览,该数据将由预期应接收表的任何函数接收:

DateTime[CalendarYear]ProductCategory[ProductCategoryName][Sales Amount (USD)][Discount Amount (USD)]
2008Bikes12968255.4236167.6592
2005Bikes6958251.0434231.1621
2006Bikes18901351.08178175.8399
2007Bikes24256817.5276065.992
2008组件2008052.70639.9266
2005组件574256.98650
2006组件3428213.05948.7674
2007组件5195315.2164226.0444
2008Clothing366507.8444151.1235
2005Clothing31851.162890.9593
2006Clothing455730.97294233.039
2007Clothing815853.286812489.3835
2008Accessories153299.924865.5945
2005Accessories18594.47824.293
2006Accessories86612.74631061.4872
2007Accessories275794.84034756.6546

使用 ROLLUP

添加 ROLLUP 语法后,通过将汇总行添加到 groupBy_columnName 列的结果中来修改 SUMMARIZE 函数的行为。 ROLLUP 只能在 SUMMARIZE 表达式中使用。

示例

下面的示例向 SUMMARIZE 函数调用的 Group-By 列添加汇总行:

SUMMARIZE(ResellerSales_USD        , ROLLUP( DateTime[CalendarYear], ProductCategory[ProductCategoryName])        , "Sales Amount (USD)", SUM(ResellerSales_USD[SalesAmount_USD])        , "Discount Amount (USD)", SUM(ResellerSales_USD[DiscountAmount])  )  

返回下表,

DateTime[CalendarYear]ProductCategory[ProductCategoryName][Sales Amount (USD)][Discount Amount (USD)]
2008Bikes12968255.4236167.6592
2005Bikes6958251.0434231.1621
2006Bikes18901351.08178175.8399
2007Bikes24256817.5276065.992
2008组件2008052.70639.9266
2005组件574256.98650
2006组件3428213.05948.7674
2007组件5195315.2164226.0444
2008Clothing366507.8444151.1235
2005Clothing31851.162890.9593
2006Clothing455730.97294233.039
2007Clothing815853.286812489.3835
2008Accessories153299.924865.5945
2005Accessories18594.47824.293
2006Accessories86612.74631061.4872
2007Accessories275794.84034756.6546
200815496115.8941224.3038
20057582953.674326.4144
200622871907.85184419.1335
200730543780.84297538.0745
76494758.25527507.9262

使用 ROLLUPGROUP

ROLLUP 语法中添加 ROLLUPGROUP 可用于防止汇总行中出现部分小计。 ROLLUPGROUP 只能在 ROLLUPROLLUPADDISSUBTOTALROLLUPISSUBTOTAL 表达式内使用。

示例

以下示例仅显示所有年份和类别的总计,而不显示所有类别的每年的小计:

SUMMARIZE(ResellerSales_USD        , ROLLUP(ROLLUPGROUP( DateTime[CalendarYear], ProductCategory[ProductCategoryName]))        , "Sales Amount (USD)", SUM(ResellerSales_USD[SalesAmount_USD])        , "Discount Amount (USD)", SUM(ResellerSales_USD[DiscountAmount])  )  

返回下表,

DateTime[CalendarYear]ProductCategory[ProductCategoryName][Sales Amount (USD)][Discount Amount (USD)]
2008Bikes12968255.4236167.6592
2005Bikes6958251.0434231.1621
2006Bikes18901351.08178175.8399
2007Bikes24256817.5276065.992
2008组件2008052.70639.9266
2005组件574256.98650
2006组件3428213.05948.7674
2007组件5195315.2164226.0444
2008Clothing366507.8444151.1235
2005Clothing31851.162890.9593
2006Clothing455730.97294233.039
2007Clothing815853.286812489.3835
2008Accessories153299.924865.5945
2005Accessories18594.47824.293
2006Accessories86612.74631061.4872
2007Accessories275794.84034756.6546
76494758.25527507.9262

使用 ISSUBTOTAL

使用 ISSUBTOTAL,你可以在 SUMMARIZE 表达式中创建另一列,如果该行包含给定为 ISSUBTOTAL 参数的列的小计值,则返回 True,否则返回 False。 ISSUBTOTAL 只能在 SUMMARIZE 表达式中使用。

示例

下面的示例为 SUMMARIZE() 函数调用中的每个 ROLLUP 列生成一个 ISSUBTOTAL 列:

SUMMARIZE(ResellerSales_USD        , ROLLUP( DateTime[CalendarYear], ProductCategory[ProductCategoryName])        , "Sales Amount (USD)", SUM(ResellerSales_USD[SalesAmount_USD])        , "Discount Amount (USD)", SUM(ResellerSales_USD[DiscountAmount])        , "Is Sub Total for DateTimeCalendarYear", ISSUBTOTAL(DateTime[CalendarYear])        , "Is Sub Total for ProductCategoryName", ISSUBTOTAL(ProductCategory[ProductCategoryName])  )  

返回下表,

[Is Sub Total for DateTimeCalendarYear][Is Sub Total for ProductCategoryName]DateTime[CalendarYear]ProductCategory[ProductCategoryName][Sales Amount (USD)][Discount Amount (USD)]
falseFALSE
FALSEfalse2008Bikes12968255.4236167.6592
falsefalse2005Bikes6958251.0434231.1621
FALSEFALSE2006Bikes18901351.08178175.8399
falsefalse2007Bikes24256817.5276065.992
falsefalse2008组件2008052.70639.9266
falsefalse2005组件574256.98650
falseFALSE2006组件3428213.05948.7674
falsefalse2007组件5195315.2164226.0444
falsefalse2008Clothing366507.8444151.1235
falsefalse2005Clothing31851.162890.9593
falseFALSE2006Clothing455730.97294233.039
falsefalse2007Clothing815853.286812489.3835
falsefalse2008Accessories153299.924865.5945
falsefalse2005Accessories18594.47824.293
falseFALSE2006Accessories86612.74631061.4872
falsefalse2007Accessories275794.84034756.6546
falseTRUE
FALSEtrue200815496115.8941224.3038
falsetrue20057582953.674326.4144
falsetrue200622871907.85184419.1335
falsetrue200730543780.84297538.0745
TRUEtrue76494758.25527507.9262

请参阅

SUMMARIZECOLUMNS

results matching ""

    No results matching ""