[英]Issue with aggregate power BI SUM
I'm trying to replicate a business calculation that exists in my environment on PowerBI, but I'm not getting what I expect as a result.我正在尝试在 PowerBI 上复制我的环境中存在的业务计算,但我没有得到我期望的结果。
I have 2 tables that I made as an example and replicate the real life problem.我有 2 张表作为示例,并复制了现实生活中的问题。
Table Sales:表销售:
dateSold Sector Idsale NPS
01/12/2021 A 1 good
01/11/2021 A 2 bad
01/11/2021 A 3 good
01/11/2021 B 4 bad
01/10/2021 A 5 bad
01/10/2021 B 6 good
01/10/2021 B 7 good
01/09/2021 A 8 good
01/09/2021 A 9 good
01/09/2021 A 10 good
And Weights table:和重量表:
SECTOR Weight
A 0,7
B 0,3
I created some fields to do my math and they do what I expect, but the last field doesnt.我创建了一些字段来做我的数学,他们做我所期望的,但最后一个字段没有。 I did a COUNT for GOOD and BAD and total values on the field NPS using this method:
我使用这种方法对字段 NPS 上的 GOOD 和 BAD 和总值进行了计数:
QuantityGOOD =
CALCULATE(
COUNTA(Sales[Idsale])
, DATESINPERIOD(Sales[dateSold], SELECTEDVALUE(Sales[dateSold]), -3, MONTH)
, Sales[NPS] == "good"
)
Then Created a field with the math using my fields:然后使用我的字段创建了一个带有数学的字段:
NPSCalculated =
[QuantityGOOD] / [QuantityTotal] - [QuantityBad] / [QuantityTotal]
Then in the last step I have to multiply this value by the weights in the other table, and I tryed this:然后在最后一步中,我必须将此值乘以另一个表中的权重,然后我尝试了这个:
FinalValue =
CALCULATE(
SUMX(
SUMMARIZE(Sales ,Sales[dateSold], weights[Sector]),
[NPSCalculated] *
CALCULATE(
AVERAGE(weights[weight]))))
But this code cuts out the values of the sector A that exists in the previous months and doesnt exist in the target month.但是这段代码去掉了前几个月存在的扇区 A 的值,并且在目标月份不存在。 It returns the sum without the part missing.
它返回总和而不丢失部分。
SaleDate Sector bad good total NPS weight FinalValue
2021-12 A 2 2 4 0 0,7 0
2021-12 B 1 2 3 0,333 0,3 0,1
I need to get the results of the column FinalValue as above (did it in excel for 2021-12 only), but instead I get only the fist line on PBI.我需要得到上述列 FinalValue 的结果(仅在 2021-12 年在 excel 中完成),但我只得到 PBI 的第一行。 Can you guys help me?
你们能帮帮我吗?
CALCULATE(
SUMX(
CALCULATETABLE(
SUMMARIZE(Sales ,Sales[dateSold], weights[Sector])
,DATESINPERIOD(Sales[dateSold], SELECTEDVALUE(Sales[dateSold]), -3, MONTH)
)
,[NPSCalculated] *
CALCULATE(
AVERAGE(weights[weight])
)
)
)
Make sure that the dataset is loaded perfectly.确保数据集已完美加载。
In the table visual, replace [dateSold] with [Month], which will let the table visual get a Cartesian product of [month] and [SECTOR].在表格视觉中,将 [dateSold] 替换为 [Month],这将使表格视觉获得 [month] 和 [SECTOR] 的笛卡尔积。
And change the parameter in your measure DATESINPERIOD().并更改测量 DATESINPERIOD() 中的参数。 Replace the dateSold column with the new date column.
将 dateSold 列替换为新的日期列。 DATESINPERIOD('Sales'[dateSold], MIN('Calendar'[Date]),-3,MONTH)) dates in period
DATESINPERIOD('Sales'[dateSold], MIN('Calendar'[Date]),-3,MONTH))期间的日期
I need to get the results of the column FinalValue as above (did it in excel for 2021-12 only), but instead I get only the first line on PBI.我需要得到上述列 FinalValue 的结果(仅在 2021-12 年在 excel 中完成),但我只得到 PBI 的第一行。 Can you guys help me?
你们能帮帮我吗?
Then in the last step, I have to multiply this value by the weights in the other table, and I tried this:然后在最后一步,我必须将此值乘以另一个表中的权重,我尝试了这个:
FinalValue = CALCULATE( SUMX( SUMMARIZE(Sales,Sales[dateSold], weights[Sector]), [NPSCalculated] * CALCULATE( AVERAGE(weights[weight])))) FinalValue = CALCULATE(SUMX(SUMMARIZE(Sales,Sales[dateSold], weights[Sector]), [NPSCalculated] * CALCULATE(AVERAGE(weights[weight]))))
Instead of this if we use this code then the expected output will be shown as the result FinalValue = VAR _s = ADDCOLUMNS ( CROSSJOIN ( VALUES ( 'Calendar'[Month] ), 'Weight' ), "final", [Weight] * [NPSCalculated] ) RETURN SUMX ( _s, [final] ) Result如果我们使用这个代码而不是这个,那么预期的 output 将显示为结果 FinalValue = VAR _s = ADDCOLUMNS ( CROSSJOIN ( VALUES ( 'Calendar'[Month] ), 'Weight' ), "final", [Weight] * [NPSCalculated] ) RETURN SUMX ( _s, [final] )结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.