如何创建显示上个月计数的度量值 (Power BI)
How to create a measure that show the count on previous month (PowerBI)
大家好,
我想在矩阵 table 中创建一个列来显示上个月 OK
的计数,我将度量命名为 Prev Month OK count
,如上面的屏幕截图所示。但是,根据我的尝试,输出不是我想要的。这是我的公式:
Prev Month OK count = CALCULATE([OK count], DATEADD('Aggregate'[Intake],-1,MONTH))
即使我在 DATEADD
中将 MONTH
参数更改为 QUARTER
,它也不起作用,总计中只有一个我不确定的值这个值是什么意思。
上面的屏幕截图是我想要的预期输出。请注意 [OK count]
也是一个度量。
任何帮助或建议将不胜感激!
日期列的屏幕截图
您可以在 Power Query 中执行此操作并使用以下代码创建一个新的 table-
let your table name is your_old_table_name
let you have these 2 column there - date and value
现在创建一个新的 table **your_new_table_name" 如下-
let
Source = your_old_table_name,
#"Grouped Rows" = Table.Group(Source, {"date"}, {{"_sum", each List.Sum([value]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"date", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index] + 1),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Index"}, #"Added Custom", {"Custom"}, "Added Custom", JoinKind.LeftOuter),
#"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"_sum"}, {"Added Custom._sum"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom",{"Index", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Added Custom._sum", "previous_date_sum"}})
in
#"Renamed Columns"
您将得到类似于以下的输出-
大家好,
我想在矩阵 table 中创建一个列来显示上个月 OK
的计数,我将度量命名为 Prev Month OK count
,如上面的屏幕截图所示。但是,根据我的尝试,输出不是我想要的。这是我的公式:
Prev Month OK count = CALCULATE([OK count], DATEADD('Aggregate'[Intake],-1,MONTH))
即使我在 DATEADD
中将 MONTH
参数更改为 QUARTER
,它也不起作用,总计中只有一个我不确定的值这个值是什么意思。
上面的屏幕截图是我想要的预期输出。请注意 [OK count]
也是一个度量。
任何帮助或建议将不胜感激!
日期列的屏幕截图
您可以在 Power Query 中执行此操作并使用以下代码创建一个新的 table-
let your table name is your_old_table_name
let you have these 2 column there - date and value
现在创建一个新的 table **your_new_table_name" 如下-
let
Source = your_old_table_name,
#"Grouped Rows" = Table.Group(Source, {"date"}, {{"_sum", each List.Sum([value]), type nullable number}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"date", Order.Ascending}}),
#"Added Index" = Table.AddIndexColumn(#"Sorted Rows", "Index", 1, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index] + 1),
#"Merged Queries" = Table.NestedJoin(#"Added Custom", {"Index"}, #"Added Custom", {"Custom"}, "Added Custom", JoinKind.LeftOuter),
#"Expanded Added Custom" = Table.ExpandTableColumn(#"Merged Queries", "Added Custom", {"_sum"}, {"Added Custom._sum"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Added Custom",{"Index", "Custom"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Added Custom._sum", "previous_date_sum"}})
in
#"Renamed Columns"
您将得到类似于以下的输出-