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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Knelio
Frequent Visitor

Index on DAX if formula to report properly graphs

Hi all,

I've the following formula:

Expiration Ageing =
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<0,"Expired",
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<=30,"Expires in 30 days",
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<=90,"Expires in 3 monhts",
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<=180,"Expires in 6 months",
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<=270,"Expires in 9 months",
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE], DAY)<=360,"Expires in 12 months", "Expires over 12 months"))))))
 
However on my graphs the sorting is not working out - in Power Editor I've this done fine, however in this data, it's only Direct Query, hence can be only DAX. Anyway to have the index added to the above formula or needs to have an additional formula to use the sorting?
Appreciate your support on this.
Thanks,
2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @Knelio 
You can add a calculated column based on Expiration Ageing by ranking it like:

if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<0,1,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=30,2,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=90,3,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=180,4,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=270,5,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=360,5))))))

and then sort the Expiration Ageing by this column

Ritaf1983_0-1697792292339.png

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Ritaf1983
Super User
Super User

@Knelio 
Yep, syntax problem : []'

Ritaf1983_0-1697804030588.png

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

5 REPLIES 5
Ritaf1983
Super User
Super User

@Knelio 
Yep, syntax problem : []'

Ritaf1983_0-1697804030588.png

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
Ritaf1983
Super User
Super User

Hi @Knelio 
You can add a calculated column based on Expiration Ageing by ranking it like:

if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<0,1,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=30,2,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=90,3,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=180,4,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=270,5,
if(DATEDIFF(TODAY(),'Table'[EXPIRATION_DATE]DAY)<=360,5))))))

and then sort the Expiration Ageing by this column

Ritaf1983_0-1697792292339.png

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thanks Rita, I'm having an error from the 4th line - it seems like it is not accepting the whole formula, only till this moment 180,4. If I close here, it will be ok. What can be the issue now? Thanks in advance!

 

Knelio_0-1697803555037.png

 

 

Knelio
Frequent Visitor

Thanks a lot! Works perfectly now!

@Knelio glad to help 🙂

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors