Forum Discussion
cqueiroz2222
1 year agoHelper I
Power BI doing wrong calculations
Hello, I'm making a table that calculates the previous month and adds it to the current month's result. Power bi makes the first line correctly, but then the calculations are wrong as you can see in...
- 1 year ago
To ensure the cumulative total is calculated correctly for each month without relying on intermediate or potentially blank values, we can use a SUMX approach. This modified measure iterates over all dates up to and including the current month and adds up the Result values.
Here's the modified measure to accumulate properly:
Cumulative Total = VAR CurrentDate = MAX('Calendar'[Date]) RETURN SUMX( FILTER( ALL('Calendar'), 'Calendar'[Date] <= CurrentDate ), [Result] )- CurrentDate: This variable captures the current row's date in the context, which acts as the endpoint for our cumulative calculation.
- FILTER(ALL('Calendar'), 'Calendar'[Date] <= CurrentDate): This filter retrieves all rows from the Calendar table up to the current date, removing any filters that might interfere.
- SUMX(..., [Result]): By iterating over each date in the filtered range, this formula sums up all [Result] values up to the CurrentDate, ensuring an accurate cumulative calculation.
Best regards,
cqueiroz2222
1 year agoHelper I
Now it worked, thank you for your help!!! 😄
cqueiroz2222
1 year agoHelper I
Hello, DataNinja777 , me again! 😃
Can you please help me to add one more condition (if it would be possible)
when my last month's result be positive (dec/23 =64.228)
next (jan/24 = 138.023) C/C measure must repeat the Result
In excel it would be:
=SE(E20<0;(D21+E20);D21)
E20 = previous month (superior line)
D21 = [Result]