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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
STC-EDR
New Member

Help on DAX to compute differences for multiple variables

Hi, I am struggling to come up with a DAX solution to compute the differences of multiple selected forecast versions.

 

First, I will select two forecast versions on my slicers, which will be shown across 12 months in a table. 

Slicers.jpg

 

Next, I want to derive the difference between the two versions by months as a comparison in the last line:

output.jpg

 

 

 

 

My current dataset is modelled as follows.
The column under Version contains columns consisting from Apr-24 to Mar-25 sequentially, and period runs from JAN to DEC:
model.jpg



 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thanks and appreciate any help gathered. 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1742876286380.png

 

 

Jihwan_Kim_0-1742876204535.png

 

INDEX function (DAX) - DAX | Microsoft Learn

 

expected result measure: = 
VAR _diff =
    CALCULATE (
        SUM ( forecast[Value] ),
        INDEX (
            1,
            ALLSELECTED ( forecast[Version], forecast[Version sort] ),
            ORDERBY ( forecast[Version sort], ASC )
        )
    )
        - CALCULATE (
            SUM ( forecast[Value] ),
            INDEX (
                1,
                ALLSELECTED ( forecast[Version], forecast[Version sort] ),
                ORDERBY ( forecast[Version sort], DESC )
            )
        )
VAR _result =
    CALCULATE (
        SUM ( forecast[Value] ),
        KEEPFILTERS ( forecast[Version] IN VALUES ( 'version'[Version] ) )
    )
RETURN
    IF (
        HASONEVALUE ( 'version'[Version] ),
        SWITCH (
            TRUE (),
            COUNTROWS ( VALUES ( forecast[Version] ) ) = 2, IF ( SELECTEDVALUE ( 'version'[Version] ) = "Difference", _diff, _result )
        )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1742876286380.png

 

 

Jihwan_Kim_0-1742876204535.png

 

INDEX function (DAX) - DAX | Microsoft Learn

 

expected result measure: = 
VAR _diff =
    CALCULATE (
        SUM ( forecast[Value] ),
        INDEX (
            1,
            ALLSELECTED ( forecast[Version], forecast[Version sort] ),
            ORDERBY ( forecast[Version sort], ASC )
        )
    )
        - CALCULATE (
            SUM ( forecast[Value] ),
            INDEX (
                1,
                ALLSELECTED ( forecast[Version], forecast[Version sort] ),
                ORDERBY ( forecast[Version sort], DESC )
            )
        )
VAR _result =
    CALCULATE (
        SUM ( forecast[Value] ),
        KEEPFILTERS ( forecast[Version] IN VALUES ( 'version'[Version] ) )
    )
RETURN
    IF (
        HASONEVALUE ( 'version'[Version] ),
        SWITCH (
            TRUE (),
            COUNTROWS ( VALUES ( forecast[Version] ) ) = 2, IF ( SELECTEDVALUE ( 'version'[Version] ) = "Difference", _diff, _result )
        )
    )

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors