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
Nankaina
Helper I
Helper I

Getting PREVIOUSYEAR to respond to month filter

Apologies for the cramped tables, the forum won't let me edit them to be better sizes.

 

I have several columns of data unpivoted like so:

 

DATEATTRIBUTEVALUE
Jan 2014     Column A     53
Jan 2014     

Column B     

8
Jan 2014     Column C     29
Feb 2014     Column A     56
Feb 2014     Column B     11
Feb 2014     Column C     20
.........

 

So that I can have those columns presented in a Matrix like this:

 

 FY 2020     % Change     FY 2021     % Change     FY 2022     % Change     
Column A     844-5.5%887+5.1%979+10.4%
Column B     117-1.7%163+39.3%154-5.5%
Column C     454-5.4%476+4.8%497+4.4%

 

Where you can see that the "% Change" column is showing the change for each FY's Column sum compared to the previous year's.

 

For "% Change", I'm using this measure:

 

% Change = 
Calculate(
    Divide(
        (Sum('Unpivoted Table'[Value]) - Calculate(Sum('Unpivoted Table'[Value]), PREVIOUSYEAR('Fiscal Year Table'[Date], "September 30"))),
        Calculate(Sum('Unpivoted Table'[Value]), PREVIOUSYEAR('Fiscal Year Table'[Date], "September 30"))
    ),
    allselected('Fiscal Year Table'[Fiscal Month Number])
)

 

I'm not very good about indentation, hopefully that's legible. PREVIOUSYEAR is being used since our Fiscal Years end in September.

 

But here's the problem. When I put in a Slicer to only select a certain subset of Months in the Fiscal Year (for example, it's January, so let's make it four months), I get this:

 

 FY 2020     % Change     FY 2021     % Change     FY 2022     % Change     
Column A     268-70.0%271-67.9%280-68.4%
Column B     34-71.4%58-50.4%32-80.4%
Column C     147-69.4%152-66.5%150-68.5%

 

So even though the Values are changing just fine, the "% Change" column is now comparing those values to the ENTIRE previous year! My measure is already calculating on allselected('Fiscal Year Table'[Fiscal Month Number]), so I don't know why it's not calculating the PREVIOUSYEAR value for the selected month numbers.

(To clarify, 'Fiscal Year Table'[Fiscal Month Number] is a column which labels the months 1 through 12, starting in October and ending in September)

 

What do I need to do to the DAX to fix this, so it's applying the % Change only to months within the selection?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

This specifically might help:


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

This specifically might help:


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

DATEADD! Of course! Pardon me going and making my life way harder than it had to be. Here I was thinking the PREVIOUSYEAR function was the only way to get this thing to do what it needed to.

 

The video you linked had exactly the Time Intelligence I was looking for. And not only is your solution shorter than mine, it's a general format so it can be reused! Thank you very much!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.