如何在Power BI Desktop中创建汇总每个季度数据的列

时间:2019-01-09 17:56:17

标签: powerbi dax powerquery m powerbi-desktop

问题在于最终用户想要从矩阵导出数据以使其表现出色并查看数据集中的所有列。

但是,如果我创建了一个度量并将其投入视觉中,然后“导出数据”- 只带来三列。

RunningTotal_QtrLoss = 
    CALCULATE( 
    SUM(fact_Losses[PaymentAmount]),
    FILTER(ALL(fact_Losses[DevQtr]),fact_Losses[DevQtr]<=MAX(fact_Losses[DevQtr])))

enter image description here

enter image description here

因此,我试图避免在Power BI中使用measure,以便在导出到excel时能够查看所有列。

为此,我用SQL计算了RunningTotal。但是,当我在矩阵中使用它时,它总结了价值。我不确定该如何总结。

为了解决这个问题,我想尝试在Power BI中创建列(而不是度量值),希望它可以让我提取所有列的原始数据。
-================================================ =============

如何简单地创建一个自定义列(通过“编辑查询”)Sum_Qtr,该列将为我提供sum(Premium)的季度和年份?

enter image description here

1 个答案:

答案 0 :(得分:0)

one way .. put in a total for all instances, then use if to replace most of them with nulls based on adjacent row

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
TotalAmountAdded = Table.AddColumn(Source, "Total Amount",(i) => List.Sum(Table.SelectRows(Source, each ([Year] = i[Year] and [Quarter] = i[Quarter]))[Premium]), type number),
#"Added Index" = Table.AddIndexColumn(TotalAmountAdded, "Index", 0, 1),
#"Added Custom" = Table.AddColumn(#"Added Index", "Sum_Qtr", each if [Index] = 0 then [Total Amount] else if Source{[Index]}[Quarter]=Source{[Index]-1}[Quarter] and Source{[Index]}[Year]=Source{[Index]-1}[Year] then null else [Total Amount]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Total Amount", "Index"})
in #"Removed Columns"