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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
codyraptor
Resolver I
Resolver I

DAX compare months in ascending vs months in descending

I know this is probably a strange request...haven't seen too much on this.  I need to calculate Jan - Dec metrics...but display them in reverse.  Below is an example....  I want PY Q3-4 to align with Current year Q1-2...and PY Q1-2 to align with Current Year Q3-4.  Anyone know of a blog post about doing something like this?  The end result will display current year actuals...but I plan to use this calculation for future months.

codyraptor_1-1659045891123.png

 

 

 

1 ACCEPTED SOLUTION
codyraptor
Resolver I
Resolver I

I found a result that seems to work for me by just adding specific months to the max month.  Thanks!

View solution in original post

4 REPLIES 4
codyraptor
Resolver I
Resolver I

I found a result that seems to work for me by just adding specific months to the max month.  Thanks!

v-yalanwu-msft
Community Support
Community Support

Hi, @codyraptor ;

please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

codyraptor
Resolver I
Resolver I

The dax I used to pull each month is not efficient.  It's taking quite a bit of time to calculate each month.  I've tried to use a fitler only on the date..and possibly pass the measure 1 time through the variable like below...but I get zero results.  Any suggestions?

 

Var SelectedMonth = max('Dispatch Date'[Dispatch Month Num])
Var MonthCalc = SWITCH(TRUE(),
SelectedMonth = 1,  DATESINPERIOD('Dispatch Date'[Dispatch Date], SelectedMonth, -1, Month),
SelectedMonth = 2,  DATESINPERIOD('Dispatch Date'[Dispatch Date], SelectedMonth, -3, Month))
Return
Calculate( [Disp Ratio Spread Baseline], KEEPFILTERS('Dispatch Date'[Dispatch Date] = MonthCalc))

codyraptor
Resolver I
Resolver I

I can break this down by month and it works...just really long dax.  Possible ways to make this cleaner?

SWITCH(TRUE(),
max('Dispatch Date'[Dispatch Month Num])=1, CALCULATE([Measure], dateadd('Dispatch Date'[Dispatch Date],-1,Month)),
max('Dispatch Date'[Dispatch Month Num])=2, CALCULATE([Measure],, dateadd('Dispatch Date'[Dispatch Date],-3,Month)))

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors