Forum Discussion
Totals incorrect for visual level calculation
- Anonymous2 years ago
Hi,TrevLc
Thank you for your replay
If you have more than one product and are calculating the difference between the current day's and previous day's quantities for each product on a row-by-row basis, and ultimately returning the correct sum of the differences, you can refer to the test I've done below
Here is my test result:Versus previous = VAR prev=IF([Product]=PREVIOUS([Product]), [M_Amount_value] - PREVIOUS([M_Amount_value]), [M_Amount_value]) VAR differ= SUMX(VALUES([Date]), CALCULATE(prev) ) return IF(ISINSCOPE([Date]), differ, [Sum of C_Difference_3] )C_Difference_3 = VAR CurrentValue=[Amount] VAR PreviousValue = CALCULATE( MAX('Table2'[Amount]), FILTER( ALL('Table2'), 'Table2'[Product] = EARLIER('Table2'[Product]) && 'Table2'[Date] < EARLIER('Table2'[Date]) ) ) RETURN CurrentValue -PreviousValueHere is my test data:
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks so much.
How would I adjust the formula if I had multiple products? So each product has an amount per date... for example, here could be some data
Hi,TrevLc
Thank you for your replay
If you have more than one product and are calculating the difference between the current day's and previous day's quantities for each product on a row-by-row basis, and ultimately returning the correct sum of the differences, you can refer to the test I've done below
Here is my test result:
Versus previous =
VAR prev=IF([Product]=PREVIOUS([Product]),
[M_Amount_value] - PREVIOUS([M_Amount_value]),
[M_Amount_value])
VAR differ=
SUMX(VALUES([Date]),
CALCULATE(prev)
)
return
IF(ISINSCOPE([Date]),
differ,
[Sum of C_Difference_3]
)
C_Difference_3 =
VAR CurrentValue=[Amount]
VAR PreviousValue = CALCULATE(
MAX('Table2'[Amount]),
FILTER(
ALL('Table2'),
'Table2'[Product] = EARLIER('Table2'[Product]) &&
'Table2'[Date] < EARLIER('Table2'[Date])
)
)
RETURN
CurrentValue -PreviousValue
Here is my test data:
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.