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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MarshalSK
Resolver I
Resolver I

Calculating the difference dynamically, based on Year selection

Hi Folks, I need asssitance to acheieve below scenario.

 

Trying to calculate the sales difference for year on year and for each product. By default, all years will be dispayed, the main cache is if the user selects different year how to calculated. For example: if user selectes 2019, 2021, 2023.

 

Data:

MarshalSK_0-1704736423119.png

Expected result:

MarshalSK_1-1704736454252.png

 

   

3 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your semantic model.

 

Jihwan_Kim_0-1704736924763.png

 

Jihwan_Kim_1-1704737280190.png

 

 

compare to the previous within the slicer selection: = 
VAR _currentselectsales =
    SUM ( Sales[Sales] )
VAR _currentselectyear =
    MAX ( 'Year'[Year] )
VAR _prevselectyear =
    MAXX (
        FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ),
        'Year'[Year]
    )
VAR _prevselectsales =
    CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear )
RETURN
    IF ( NOT ISBLANK ( _prevselectsales ), _currentselectsales - _prevselectsales )

 

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

MarshalSK
Resolver I
Resolver I

6 REPLIES 6
MarshalSK
Resolver I
Resolver I

@Jihwan_Kim  Perfect.

Jihwan_Kim
Super User
Super User

Hi, I am not sure if I understood your question correctly, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your semantic model.

 

Jihwan_Kim_0-1704736924763.png

 

Jihwan_Kim_1-1704737280190.png

 

 

compare to the previous within the slicer selection: = 
VAR _currentselectsales =
    SUM ( Sales[Sales] )
VAR _currentselectyear =
    MAX ( 'Year'[Year] )
VAR _prevselectyear =
    MAXX (
        FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ),
        'Year'[Year]
    )
VAR _prevselectsales =
    CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear )
RETURN
    IF ( NOT ISBLANK ( _prevselectsales ), _currentselectsales - _prevselectsales )

 

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.

@Jihwan_Kim  One more quick question. How to apply filter>70, on top of the above result?

Perfect

Hi, I am not sure if I understood your question correctly, but do you mean something like below?

 

Jihwan_Kim_0-1704822360780.png

 

compare to the previous within the slicer selection: = 
VAR _currentselectsales =
    SUM ( Sales[Sales] )
VAR _currentselectyear =
    MAX ( 'Year'[Year] )
VAR _prevselectyear =
    MAXX (
        FILTER ( ALLSELECTED ( 'Year' ), 'Year'[Year] < _currentselectyear ),
        'Year'[Year]
    )
VAR _prevselectsales =
    CALCULATE ( SUM ( Sales[Sales] ), 'Year'[Year] = _prevselectyear )
RETURN
    IF (
        NOT ISBLANK ( _prevselectsales )
            && _currentselectsales - _prevselectsales > 70,
        _currentselectsales - _prevselectsales
    )

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.

I'm trying to bring in the same functionality and trying to use this same DAX but it's throwing an error. 

BUSH781_0-1717602382473.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.