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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Baba
Frequent Visitor

How to show past X years by Qtr using DAX

Hello,

 

Looking some help to achive last X year (at least 5 years) data using DAX?  (Snip below on the format).  Currently I am using one measure for each year and works fine if I am selecting "2024" from the slicer above but as soon as I select any other year numbers change and doesn't show what column hearders are.  I need to show this by Qtr.  Would really appriciate help on this.

 

Thanks in advance

 

Baba_0-1711137558800.png

 

1 ACCEPTED SOLUTION
AmiraBedh
Resident Rockstar
Resident Rockstar

Can you share some data ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

3 REPLIES 3
AmiraBedh
Resident Rockstar
Resident Rockstar

First you need to create a table with the distinct values of your Years :

YearsTable = 
VAR UniqueYears = DISTINCT ( SELECTCOLUMNS ( Consolidated_Sales_From_2019, "Year", YEAR ( [Date] ) ) )
RETURN
    UniqueYears

 

AmiraBedh_0-1711823900251.png

Don't create any relationship between your fact table and the Years table :

AmiraBedh_1-1711823941699.png

 

Then create your measure for Sales :

Sales = CALCULATE(SUM(Consolidated_Sales_From_2019[Actual Sales]))

 

Create another measure to use it as a filter on the visual :

 

Sales Last 5 Years = 
 IF(MAX(Consolidated_Sales_From_2019[Year])>(MAX(YearsTable[Year])-5) && 
 MAX(Consolidated_Sales_From_2019[Year])<=MAX(YearsTable[Year]),1,0)

 

For the Year slicer, use the YearsTable (you may need to check your Quarter column): 

 

AmiraBedh_2-1711824236224.pngAmiraBedh_3-1711824278287.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
Baba
Frequent Visitor

Hi @AmiraBedh ,

I tried many different ways but wasn't able to succed to send you PBIX file or data on excel or thru table or notepad.  So below I copied the data for one year, so if you copy the data 5/6 times and change the year, that will create a data for few years for you to test.  Thanks in advance! 

 

2019Actuals4/1/201912AD100010001000L ToteLTQ2Apr4000000000000
2019Actuals6/1/201912AD100010001000L ToteLTQ2Jun6000000000000
2019Actuals5/1/201912AD100010001000L ToteLTQ2May5000000000000
2019Actuals8/1/201912AD100010001000L ToteLTQ3Aug8000000000000
AmiraBedh
Resident Rockstar
Resident Rockstar

Can you share some data ?


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.