运行 基于其他列值的总计
Running total based on other columns value
我需要计算 运行 从最大值开始的总预测金额,基于两个库存位置,每个产品一次(由于库存位置,产品编号是重复的)。例如,产品编号“1”应使用一次,总共 运行。
我的第一个代码,它没有根据项目编号独立地求和相同的预测金额。
RunningTotal1 =
VAR
CurrentAmount= Listing[Forecast Amount]
RETURN
SUMX (
FILTER (
Listing;
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
我的第二个代码,其中 运行 总数是基于库存位置,它独立计算每个位置仍然没有根据项目编号独立计算相同的预测金额。
RunningTotal2 =
VAR CurrentAmount = Listing[Forecast Amount]
VAR Location = Listing[Stock Location]
RETURN
SUMX (
FILTER (
Listing;
Listing[Stock Location] = Location &&
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
但是当我将第二个位置添加到我的公式时它给出了一个错误。
"DAX comparison operations do not support comparing values of type Text with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values."
RunningTotal3 =
VAR CurrentAmount = Listing[Forecast Amount]
VAR LocationW = Listing[Stock Location] = "Warehouse"
VAR LocationT = Listing[Stock Location] = "Total Stock"
RETURN
SUMX (
FILTER (
Listing;
Listing[Stock Location] = LocationW ||
Listing[Stock Location] = LocationT &&
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
我期待的是
你好@RADO,
我尝试添加为度量但未能成功,因此我添加为新列。我意识到我的代码有误,在您的图片中,第 5 和第 6 项的编号不同。我的公式是
Forecast Index = RANKX(Listing;Listing[Forecast Amount])
这是结果Forecast Index
问候
您需要在 "Listing" table 中添加一列来定义 运行 总数的顺序。您不能为此使用预测金额,因为在某些情况下不同的项目具有相同的金额(例如,项目 66 和 99),并且无法解决这些关系(哪些项目应该首先累积 - 66 或99?没办法说)。
通常,date/time 字段用于此目的,但如果您没有它们,您可以根据需要的任何规则添加索引。对于这个例子,我手动添加了 "Forecast Index" 如下:
此处的预测索引只是一个排序顺序 - 如果您按它排序,您将得到与您的 "desired result" table 完全匹配的布局。
然后,创建一个度量:
RT Expected =
VAR Current_Index = MAX ( Listing[Forecast Index] )
VAR Summary_Table =
SUMMARIZE (
FILTER (
ALL ( Listing ),
Listing[Forecast Index] <= Current_Index &&
Listing[Stock Location] <> "Without Stock" ),
Listing[Item No],
Listing[Forecast Amount] )
RETURN
SUMX ( Summary_Table, Listing[Forecast Amount] )
结果:
注意:如果您不想看到第 2 项和第 4 项,只需将它们从视觉过滤器中删除即可。
工作原理:
- 首先,我们使用 FILTER 创建一个虚拟 table,a) 忽略 "Without Stock" 个位置,b) 只保留 运行 总数所需的预测金额;
- 其次,我们使用 SUMMARIZE 按项目编号和预测金额对该虚拟 table 进行分组。分组消除重复;
- 最后,我们使用 SUMX 迭代 de-duplicated table,并对所有相关金额求和。
编辑:
您可以使用 PowerQuery 创建合适的索引:
- 在您的左侧面板中,转到 "Data",然后 select "Listing" table;
- Right-click table,select "Edit Query"。 Power BI 将带你到 Power Query window;
- 在 Power Query 中,首先,对列 "Forecast Amount" 进行降序排序。然后,对 "Item No" 列进行升序排序。这将按照您在图片中的顺序排列您的记录;
- 最后,在 Power Query window 中,转到 "Add Column",然后是 "Index Column"、select "From 1"。 Power Query 将为您创建一个索引列,并将其命名为 "Index"。您可以根据需要重命名它(即 "Forecast Index");
- 单击 "Close and Apply",然后构建我建议使用此新索引列作为输入的度量。
如果这些说明不清楚,请参阅这篇文章:
https://www.excelguru.ca/blog/2018/06/14/ranking-method-choices-in-power-query/
我需要计算 运行 从最大值开始的总预测金额,基于两个库存位置,每个产品一次(由于库存位置,产品编号是重复的)。例如,产品编号“1”应使用一次,总共 运行。
我的第一个代码,它没有根据项目编号独立地求和相同的预测金额。
RunningTotal1 =
VAR
CurrentAmount= Listing[Forecast Amount]
RETURN
SUMX (
FILTER (
Listing;
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
我的第二个代码,其中 运行 总数是基于库存位置,它独立计算每个位置仍然没有根据项目编号独立计算相同的预测金额。
RunningTotal2 =
VAR CurrentAmount = Listing[Forecast Amount]
VAR Location = Listing[Stock Location]
RETURN
SUMX (
FILTER (
Listing;
Listing[Stock Location] = Location &&
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
但是当我将第二个位置添加到我的公式时它给出了一个错误。
"DAX comparison operations do not support comparing values of type Text with values of type True/False. Consider using the VALUE or FORMAT function to convert one of the values."
RunningTotal3 =
VAR CurrentAmount = Listing[Forecast Amount]
VAR LocationW = Listing[Stock Location] = "Warehouse"
VAR LocationT = Listing[Stock Location] = "Total Stock"
RETURN
SUMX (
FILTER (
Listing;
Listing[Stock Location] = LocationW ||
Listing[Stock Location] = LocationT &&
Listing[Forecast Amount]>= CurrentAmount);
Listing[Forecast Amount])
我期待的是
你好@RADO,
我尝试添加为度量但未能成功,因此我添加为新列。我意识到我的代码有误,在您的图片中,第 5 和第 6 项的编号不同。我的公式是
Forecast Index = RANKX(Listing;Listing[Forecast Amount])
这是结果Forecast Index
问候
您需要在 "Listing" table 中添加一列来定义 运行 总数的顺序。您不能为此使用预测金额,因为在某些情况下不同的项目具有相同的金额(例如,项目 66 和 99),并且无法解决这些关系(哪些项目应该首先累积 - 66 或99?没办法说)。
通常,date/time 字段用于此目的,但如果您没有它们,您可以根据需要的任何规则添加索引。对于这个例子,我手动添加了 "Forecast Index" 如下:
此处的预测索引只是一个排序顺序 - 如果您按它排序,您将得到与您的 "desired result" table 完全匹配的布局。
然后,创建一个度量:
RT Expected =
VAR Current_Index = MAX ( Listing[Forecast Index] )
VAR Summary_Table =
SUMMARIZE (
FILTER (
ALL ( Listing ),
Listing[Forecast Index] <= Current_Index &&
Listing[Stock Location] <> "Without Stock" ),
Listing[Item No],
Listing[Forecast Amount] )
RETURN
SUMX ( Summary_Table, Listing[Forecast Amount] )
结果:
注意:如果您不想看到第 2 项和第 4 项,只需将它们从视觉过滤器中删除即可。
工作原理:
- 首先,我们使用 FILTER 创建一个虚拟 table,a) 忽略 "Without Stock" 个位置,b) 只保留 运行 总数所需的预测金额;
- 其次,我们使用 SUMMARIZE 按项目编号和预测金额对该虚拟 table 进行分组。分组消除重复;
- 最后,我们使用 SUMX 迭代 de-duplicated table,并对所有相关金额求和。
编辑:
您可以使用 PowerQuery 创建合适的索引:
- 在您的左侧面板中,转到 "Data",然后 select "Listing" table;
- Right-click table,select "Edit Query"。 Power BI 将带你到 Power Query window;
- 在 Power Query 中,首先,对列 "Forecast Amount" 进行降序排序。然后,对 "Item No" 列进行升序排序。这将按照您在图片中的顺序排列您的记录;
- 最后,在 Power Query window 中,转到 "Add Column",然后是 "Index Column"、select "From 1"。 Power Query 将为您创建一个索引列,并将其命名为 "Index"。您可以根据需要重命名它(即 "Forecast Index");
- 单击 "Close and Apply",然后构建我建议使用此新索引列作为输入的度量。
如果这些说明不清楚,请参阅这篇文章:
https://www.excelguru.ca/blog/2018/06/14/ranking-method-choices-in-power-query/