Forum Discussion

cqueiroz2222's avatar
cqueiroz2222
Helper I
1 year ago
Solved

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...
  • DataNinja777's avatar
    DataNinja777
    1 year ago

    cqueiroz2222 ,

    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,