Forum Discussion

kfitzek's avatar
kfitzek
Regular Visitor
1 year ago
Solved

Percentage Change Over Time

Hello,   I am looking to calculate a % change over mutliple data sets. Essentially I have a file for each month with a certain amount of forecast. I want to be able to calcualte the difference betw...
  • DataNinja777's avatar
    1 year ago

    Hi kfitzek ,

     

    To calculate a dynamic percentage change between any two months in your forecast data, you should first ensure your model uses a normalized structure with a proper Date column and a related calendar table. Assuming you’ve unpivoted your forecast data so that each row has a Date and Forecast value, and you've created a DateTable with continuous dates and related it to your forecast table on the Date column, you can then introduce two disconnected copies of the DateTable for comparison. These disconnected tables will allow users to select the base and comparison dates using slicers without interfering with the main model filters.

    You can then write the following DAX measure:

    % Change Between Selected Dates = 
    VAR BaseDate = SELECTEDVALUE('DateTable_Base'[Date])
    VAR CompareDate = SELECTEDVALUE('DateTable_Compare'[Date])
    VAR BaseValue = 
        CALCULATE(
            SUM('ForecastTable'[Forecast]),
            'DateTable'[Date] = BaseDate
        )
    VAR CompareValue = 
        CALCULATE(
            SUM('ForecastTable'[Forecast]),
            'DateTable'[Date] = CompareDate
        )
    RETURN
        IF(
            NOT ISBLANK(CompareValue) && NOT ISBLANK(BaseValue),
            DIVIDE(CompareValue - BaseValue, BaseValue)
        )
    

    This approach uses clean modeling, avoids hardcoding, and leverages a proper date relationship for accuracy and flexibility. Users can now choose any two months or dates using slicers tied to the disconnected base and comparison date tables, and the measure will compute the percentage change between the corresponding forecast values dynamically.

     

    Best regards,