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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ChrisIrvin
Frequent Visitor

% Change over user selected year columns

Hi all,

 

First time poster! I'd appreciate any help you can give me with this question...

 

I need to create a dynamic matrix and line chart that shows the percentage change over selected year columns. Example below.

 

There are 10 years in the report and a user can select any combination of years. The selected years need not be contiguous, but are displayed in order (L to R). If a user adds more years, the table recalculates to reflect all possible % changes. If only 1 year is selected you'd see a blank table/chart. I think this means that a date table may not be appropriate as I want the calculation to work over non-contiguous years.

 

The result I'm looking for is exactly the same as if you used a pivot table to show % Difference From (previous).

 

So from this:

 

Category202020222023
A405379338089411576
B263250229064279059
C198641103715044
D9030743171125443
E305931760029115
Grand Total809393638961860237

 

I want this:

 

Category202020222023
A -17%22%
B -13%22%
C -44%36%
D -52%191%
E -42%65%
Grand Total -21%35%

 

And this:

 

ChrisIrvin_0-1701823352103.png

 

 

Happy to provide more info.

 

Many thanks!

 

Chris.

1 ACCEPTED SOLUTION
gmsamborn
Super User
Super User

Hi @ChrisIrvin 

Maybe try something like this.

 

Pct Chg = 
VAR _CurrentSelected = [Total Value]
VAR _PreviousSelected =
    CALCULATE(
        [Total Value],
        OFFSET(
            -1,
            ALLSELECTED( 'Table'[Year] ),
            ORDERBY( 'Table'[Year] )
        )
    )
VAR _Logic =
    DIVIDE(
        _CurrentSelected - _PreviousSelected,
        _PreviousSelected
    )
RETURN
    _Logic

 

 

View solution in original post

6 REPLIES 6
gmsamborn
Super User
Super User

Hi @ChrisIrvin 

Maybe try something like this.

 

Pct Chg = 
VAR _CurrentSelected = [Total Value]
VAR _PreviousSelected =
    CALCULATE(
        [Total Value],
        OFFSET(
            -1,
            ALLSELECTED( 'Table'[Year] ),
            ORDERBY( 'Table'[Year] )
        )
    )
VAR _Logic =
    DIVIDE(
        _CurrentSelected - _PreviousSelected,
        _PreviousSelected
    )
RETURN
    _Logic

 

 

Hi there - that solution is working super well. However there's one enhancement I'd like if possible - can the earliest year also be shown as a blank column? This is necessary because having the ability to select any combination of years means that the earliest year might not be the year previous to the earliest one displayed. I hope that makes sense!
Thank you.

Hi @ChrisIrvin 

 

I'm not really sure what you mean.  Can you show me an example?

 

Perfect! Thank you! Highly appreciated! 😎

This is a good use of OFFSET. Short, easy to understand and fast.










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
CoreyP
Solution Sage
Solution Sage

I'm not gonna lie... this took me absolutely wayyy longer than it probably should have. But, it was a bit tricky. You do need a date dimension table. IMHO, if a date exists anywhere in your model, you should always have a date dimension table in Power BI. 

 

CoreyP_0-1701835209032.png

Delta = 
VAR _currenttotal = [Total Value]
VAR _previoustotal = 
CALCULATE( 
    [Total Value] , 
        'Date'[Date].[Year] = 
            MAXX( 
                FILTER( 
                    CALCULATETABLE( 
                        VALUES( 'Date'[Date].[Year] ) , 
                        ALLSELECTED('Date'[Date].[Year] ) 
                                ) ,
                        'Date'[Date].[Year] < MAX( 'Date'[Date].[Year] ) 
                        ) , 
                'Date'[Date].[Year] 
                )
            )
VAR _delta = _currenttotal - _previoustotal
VAR _pct = DIVIDE( _delta , _previoustotal , BLANK() )

RETURN
_pct

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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