Forum Discussion

martaoldi00's avatar
martaoldi00
New Member
2 years ago
Solved

Calculate difference vs the previous period

Hello PBI Community.

 

I have a table with three columns: 1. Project Names 2. Forecast periods (1,2,3,4) and 3.Costs (€m). I need to create a visualization-table where I can see the differences between this period and the previous one for each project. This is what I've been trying so far but I cant make it work.

 

_MW Delta =
    VAR Per = MAX('Upper+Baseline'[Period])
    VAR Prev_ Period = Ult_Per - 1
    VAR Actual =
        CALCULATE(
            SUM('Upper+Baseline'[€m]),
            'Upper+Baseline'[Period] = Per
        )
    VAR Previous=
        CALCULATE(
            SUM('Upper+Baseline'[€m]),
            'Upper+Baseline'[Period] = Prev_ Period
        )
    RETURN
            Actual - Previous
  • Anonymous's avatar
    Anonymous
    2 years ago

    ryan_mayu Thanks for your contribution on this thread.

    Hi martaoldi00 ,

    I created a sample pbix file(see the attachment), please check if that is what you want. You can update the formula of your measure [_MW Delta] as below:

    _MW Delta = 
        VAR Per = SELECTEDVALUE('Upper+Baseline'[Period])
        VAR Prev_Period = Per - 1
        VAR _project=SELECTEDVALUE('Upper+Baseline'[Project Names])
        VAR Actual =
            CALCULATE(
                SUM('Upper+Baseline'[€m]),
                'Upper+Baseline'[Period] = Per
            )
        VAR Previous=
            CALCULATE(
                SUM('Upper+Baseline'[€m]),
                FILTER(ALLSELECTED('Upper+Baseline'),'Upper+Baseline'[Project Names]=_project&&'Upper+Baseline'[Period] =Prev_Period)
            )
        RETURN
              IF(ISBLANK(Previous),BLANK(), Actual - Previous)

    Best Regards

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    ryan_mayu Thanks for your contribution on this thread.

    Hi martaoldi00 ,

    I created a sample pbix file(see the attachment), please check if that is what you want. You can update the formula of your measure [_MW Delta] as below:

    _MW Delta = 
        VAR Per = SELECTEDVALUE('Upper+Baseline'[Period])
        VAR Prev_Period = Per - 1
        VAR _project=SELECTEDVALUE('Upper+Baseline'[Project Names])
        VAR Actual =
            CALCULATE(
                SUM('Upper+Baseline'[€m]),
                'Upper+Baseline'[Period] = Per
            )
        VAR Previous=
            CALCULATE(
                SUM('Upper+Baseline'[€m]),
                FILTER(ALLSELECTED('Upper+Baseline'),'Upper+Baseline'[Project Names]=_project&&'Upper+Baseline'[Period] =Prev_Period)
            )
        RETURN
              IF(ISBLANK(Previous),BLANK(), Actual - Previous)

    Best Regards

    • BIstvan's avatar
      BIstvan
      Resolver I

      Anonymous  Really amazing. 

       

      martaoldi00  I was just working on something very similar. I just want to present the way I choose to handle it.

       

      I have used the attechment from above.

       

      You can add a calculated column in the table to bring the previous values for each project.

       

      Then you can create a measure to calculate the variance in percentage

    • martaoldi00's avatar
      martaoldi00
      New Member

      The table would be like this and the measure is the €Delta:

      ProjectPeriodUnits€ Price  PeriodUnits€ Price € Delta
      Project 182121.7 92121.70
      Project 281720.2 91720.20
      Project 382828.3 92828.30
      Project 481719.7 91719.5-0.2
      Project 586047.5 960513.5
      Project 681418.5 91413.6-4.9
      Project 781821.9 92120.5-1.4