powerbi - Power-Query 和 Power BI 如何创建度量并将其联合回原始数据集
问题描述
想知道我们如何基于数据集创建度量,然后将其合并回原始数据集?
可能是更容易直观地查看问题,所以我创建了下面的图片。
PS不知何故,无论前一天或相关功能如何,我都必须以这种方式进行
谢谢
谢谢
解决方案
您可以添加一个自定义列来计算比较量,方法是查找该类别值当前行日期之前的最后一个日期的量。删除该Volume
列,将CalcType
“Individual”重命名为“Comparison”,然后将该表附加到原始表中。
这是 M 代码的样子。
let
Source = <Insert Source Here>,
#"Changed Type" = Table.TransformColumnTypes(Source,
{{"Date", type date}, {"Category", type text},
{"CalcType", type text}, {"Volume", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Comparison", each
try Table.Max(Table.SelectRows(#"Changed Type",
(C) => C[Date] < [Date] and C[Category] = [Category]), "Date")[Volume]
otherwise null, Int64.Type),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Volume"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Comparison","Volume"}}),
#"Replaced Value" = Table.ReplaceValue(#"Renamed Columns",
"Individual","Comparison",Replacer.ReplaceText,{"CalcType"}),
#"Filtered Rows" = Table.SelectRows(#"Replaced Value", each ([Volume] <> null)),
#"Appended Query" = Table.Combine({#"Changed Type", #"Filtered Rows"})
in
#"Appended Query"
推荐阅读
- amazon-web-services - Exim sender_address 与地址不同
- python - ValueError:使用 astype 时无法将字符串转换为 pandas 中的浮点数
- mysql - VS Code 不处理带有转义字符的单引号
- google-apps-script - 创建时间触发器的应用脚本不起作用
- mysql - 有什么方法可以在 MySQL 中创建用户定义的数据类型?
- flutter - 如何使用列表自定义滑块?
- google-chrome - 谷歌浏览器在打开页面后总是崩溃
- angular - ngFor 与 ngBootstrap NgbModal 打开 - Angular Bootstrap
- ansible - 如何使用 ansible expect 滚动浏览 EULA?
- sql - 分组重复数字sqlite表