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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
Anonymous
Not applicable

How to retrieve 3 previous years of data with DAX

Hei, is there a way to compact this code for showing 3 years of data?

 

Reservations present year :=
CALCULATE(
              SUM('ssas CustomerDocuments'[Dokumenter]);
                            'ssas CustomerDocuments'[Artikkel]="984 Reservation region1"||
                            'ssas CustomerDocuments'[Artikkel]="985 Reservation region2"||
                            'ssas CustomerDocuments'[Artikkel]="993 Reservation region3"||
                            'ssas CustomerDocuments'[Artikkel]="994 Reservation region4.";
                            DateTable[year]=YEAR(TODAY()))
Reservations last year :=
CALCULATE(
              SUM('ssas CustomerDocuments'[Dokumenter]);
                            'ssas CustomerDocuments'[Artikkel]="984 Reservation region1"||
                            'ssas CustomerDocuments'[Artikkel]="985 Reservation region2"||
                            'ssas CustomerDocuments'[Artikkel]="993 Reservation region3"||
                            'ssas CustomerDocuments'[Artikkel]="994 Reservation region4.";
                            DateTable[year]=YEAR(TODAY())-1)
Reservations two years ago :=
CALCULATE(
              SUM('ssas CustomerDocuments'[Dokumenter]);
                            'ssas CustomerDocuments'[Artikkel]="984 Reservation region1"||
                            'ssas CustomerDocuments'[Artikkel]="985 Reservation region2"||
                            'ssas CustomerDocuments'[Artikkel]="993 Reservation region3"||
                            'ssas CustomerDocuments'[Artikkel]="994 Reservation region4.";
                            DateTable[year]=YEAR(TODAY())-2)
1 ACCEPTED SOLUTION
JosefPrakljacic
Solution Sage
Solution Sage

Hi Dax_New_User

 

I bet you will need the parallelperiod function. 

 

Here are some guides:

https://www.youtube.com/watch?v=yVZHbKKIzDE

https://docs.microsoft.com/en-us/dax/parallelperiod-function-dax

 

If you need further help please share some example data.

 

If this post was helpful may I ask you to mark it as a solution and share some kudos 🙂

 

Have a nice day!

 

BR,

Josef

View solution in original post

1 REPLY 1
JosefPrakljacic
Solution Sage
Solution Sage

Hi Dax_New_User

 

I bet you will need the parallelperiod function. 

 

Here are some guides:

https://www.youtube.com/watch?v=yVZHbKKIzDE

https://docs.microsoft.com/en-us/dax/parallelperiod-function-dax

 

If you need further help please share some example data.

 

If this post was helpful may I ask you to mark it as a solution and share some kudos 🙂

 

Have a nice day!

 

BR,

Josef

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.