Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Calculate difference between budget versions instead of date

Hi there, I'm trying to figure out a DAX measure to calculate differences between versions of forecast.  Each month we create a new forecast.  I would like to create a waterfall chart that bridges the changes between each version of the budget.

 

  • I have a Data table (below) and Date Table.   
  • I have a relationship between these two tables with the common "date" field. 
  • I also have a slicer to toggle between apple and mango (ie. my dummy "customers"). 
  • First DAX measure  - Current Version = sum(Data[Actuals])
  • Second DAX measure - Previous Version = CALCULATE([Current Version],PREVIOUSMONTH('Date Table'[Date]))
  • Third DAX measure - Change MoM = [Current Version] - [Previous Version]


When I create a waterfall with Month (from Date Table) on the X axis, it works.  However, when I put "Version" from Data table on the X axis the numbers come out wonky.    I cannot figure why!  I was hoping the relationship to the date table would fix it....

 

VersionDate of VersionCustomerBudget
Version 1

  1-Jan-20

apple1
Version 1  1-Jan-20mango5
Version 2  1-Feb-20apple2
Version 2  1-Feb-20mango3
Version 3  15-Mar-20apple6
Version 3  15-Mar-20mango10
Version 4  6-Apr-20apple12
Version 4  6-Apr-20mango14
Version 5  25-May-20apple15
Version 5  25-May-20mango22
Version 6  15-Jul-20apple30
Version 6  15-Jul-20mango15

 

I'ved saved a copy of the PBI file - https://drive.google.com/file/d/1XCYkurpJKpTSHbx9uy1_4trANOM7Mg38/view?usp=sharing 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Sorry for the late response, but I have done the following:

  • Add the following column:
VersionID =
IF (
    SEARCH ( "+", Data[Version],, 0 ) = 0,
    LEFT ( Data[Version], 4 ) & "00",
    LEFT ( Data[Version], 4 )
        & SUBSTITUTE (
            RIGHT (
                LEFT ( Data[Version], SEARCH ( "+", Data[Version],, 0 ) - 1 ),
                SEARCH ( " ", Data[Version],, 0 ) - 3
            ),
            " ",
            "0"
        )
)

 

This was done with DAX but believe that the best option is to make it in the query editor so that you can Sort the version vby this ID:

if Text.Contains ([Version], "+")  then  
Text.Start([Version], 4) &
Text.PadStart(
Text.End(Text.Start([Version],Text.PositionOf([Version], "+")) ,

Text.PositionOf([Version], "+") - 
Text.PositionOf([Version], " ") -1
 ), 2, "0")

else Text.Start([Version], 4) & "00"

Now add the following code:

 

Previous Version by version _ = 
VAR currentVersion =
    SELECTEDVALUE ( Data[VersionID] )
VAR PreviousVersion =
    IF(RIGHT(currentVersion, 2 )  = "00", currentVersion - 100, currentVersion - 1)
VAR temp_table =
    FILTER (
        SUMMARIZE ( ALLSELECTED ( Data ), Data[VersionID], "Actuals", [Current Version] ),
        Data[VersionID] = PreviousVersion
    )
RETURN
    SUMX ( temp_table, [Actuals] )

 

Has you can see below and in attach PBIX the Calculation are matching but be aware that the split for the 2021 budget is not correct because of the dates leap since budget and actuals for january are in the same date.

 

MFelix_0-1613483653022.png

 

In this file I have created a hierarchy to give corrects values in X-Axis but as I refere if you create the column in the query editor then you can sort the Version column by the versionId and no need for the hierarchy.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hello @MFelix and other users of the community

 

I was thinking of doing a new post, but will follow up here first.

 

The naming convention of the versions have since gotten more complicated

2018 actuals, 2019 actuals, 2020 actuals, 2021 1+11 forecast, 2021 2+10 forecast, 2021 3+9 forecast, etc.

 

I was wondering how can I tell Power BI that the "previous version" of 2019 actuals is 2018 actuals, and the previous version of 2021 3+9 forecast is 2021 2+10 forecast.   See attached file here

 https://drive.google.com/file/d/1kY5ge8YevRCDAwbkhsUkZPkAYDFTSKw3/view?usp=sharing  

 

Thank you!

Hi @Anonymous ,

 

Sorry for the late response, but I have done the following:

  • Add the following column:
VersionID =
IF (
    SEARCH ( "+", Data[Version],, 0 ) = 0,
    LEFT ( Data[Version], 4 ) & "00",
    LEFT ( Data[Version], 4 )
        & SUBSTITUTE (
            RIGHT (
                LEFT ( Data[Version], SEARCH ( "+", Data[Version],, 0 ) - 1 ),
                SEARCH ( " ", Data[Version],, 0 ) - 3
            ),
            " ",
            "0"
        )
)

 

This was done with DAX but believe that the best option is to make it in the query editor so that you can Sort the version vby this ID:

if Text.Contains ([Version], "+")  then  
Text.Start([Version], 4) &
Text.PadStart(
Text.End(Text.Start([Version],Text.PositionOf([Version], "+")) ,

Text.PositionOf([Version], "+") - 
Text.PositionOf([Version], " ") -1
 ), 2, "0")

else Text.Start([Version], 4) & "00"

Now add the following code:

 

Previous Version by version _ = 
VAR currentVersion =
    SELECTEDVALUE ( Data[VersionID] )
VAR PreviousVersion =
    IF(RIGHT(currentVersion, 2 )  = "00", currentVersion - 100, currentVersion - 1)
VAR temp_table =
    FILTER (
        SUMMARIZE ( ALLSELECTED ( Data ), Data[VersionID], "Actuals", [Current Version] ),
        Data[VersionID] = PreviousVersion
    )
RETURN
    SUMX ( temp_table, [Actuals] )

 

Has you can see below and in attach PBIX the Calculation are matching but be aware that the split for the 2021 budget is not correct because of the dates leap since budget and actuals for january are in the same date.

 

MFelix_0-1613483653022.png

 

In this file I have created a hierarchy to give corrects values in X-Axis but as I refere if you create the column in the query editor then you can sort the Version column by the versionId and no need for the hierarchy.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

Hi @MFelix 

 

https://drive.google.com/file/d/1XCYkurpJKpTSHbx9uy1_4trANOM7Mg38/view?usp=sharing 

 

Can you try this one?  I uploaded my file to my google drive and changed the setting so anyone with the link can access.  If ther eis a better way to upload a file in this forum, let me know!

Hi @Anonymous ,

 

The information you are getting is based on context what this means is that since your Previous versions is based on the date it will return correct when you have the date in your context when you change the context (remove the date) it will get incorrect.

 

If you had a measure that picks up the version code, I'm assuming that each month has the name Version 1, version 2, and so on:

 

Add the following measure:

Previous Version by version =
VAR currentVersion =
    SELECTEDVALUE ( Data[Version] )
VAR Find_Version =
    SEARCH ( " ", currentVersion,, LEN ( currentVersion ) )
VAR VersionNumber =
    RIGHT ( currentVersion, LEN ( currentVersion ) - Find_Version )
VAR temp_table =
    FILTER (
        SUMMARIZE ( ALLSELECTED ( Data ), Data[Version], "Actuals", [Current Version] ),
        Data[Version] = "Version " & VersionNumber - 1
    )
RETURN
    SUMX ( temp_table, [Actuals] )



Change MoM by version = [Current Version] - [Previous Version by version]

 

Result below and in attach file:

MFelix_0-1612282236885.png

 

Be aware that since your measure is based on previous month and the Version 5 to version 6 goes from May to July the last 2 column by date are summarized on the last column by version.

 

PBIX file attach.

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MFelix
Super User
Super User

Hi @Anonymous 

 

The file is asking for a password can you please share it without password.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors