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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Optimusprime_25
Resolver I
Resolver I

How to Sort Sub Header in Switch Case in DAX

I have to sort the sub header columns 

values =
var ABC_MTD
var ABC_YTD
var XYZ_MTD
var XYZ_YTD
RETURN
SWITCH(
MAX(Table[Sub_Header]),
"MTD", ABC_MTD,
"YTD", ABC_YTD,
"MTD", XYZ_MTD,
"YTD", XYZ_YTD)
 
Above we are able to create the measure but while pulling this values MTD and YTD values are not correct because it has same value for bpth columns.
 
how to sort or differentiate here without changing the column names. As it should be MTD and YTD for both columns.
1 ACCEPTED SOLUTION
Optimusprime_25
Resolver I
Resolver I

I have found the solution for this topic.

In above case we have sub headers are repeating as MTD and YTD for 8 columns.

What we did was in switch function we have used space for MTD and YTD so that each and every sub ehader will be unique

 

Ex: 1. "MTD", "YTD"

     2. " MTD", " YTD"

     3. "  MTD", "  YTD"

 

We have given extra space so that dax considers each sub header as unique and sort accordingly.

View solution in original post

2 REPLIES 2
Optimusprime_25
Resolver I
Resolver I

I have found the solution for this topic.

In above case we have sub headers are repeating as MTD and YTD for 8 columns.

What we did was in switch function we have used space for MTD and YTD so that each and every sub ehader will be unique

 

Ex: 1. "MTD", "YTD"

     2. " MTD", " YTD"

     3. "  MTD", "  YTD"

 

We have given extra space so that dax considers each sub header as unique and sort accordingly.

amitchandak
Super User
Super User

@Optimusprime_25 , The information you have provided is not making the problem clear to me. Can you please explain with an example?

refer if my blog on a similar topic can help

 

https://medium.com/chandakamit/power-bi-when-i-felt-lazy-and-i-needed-too-many-measures-ed8de20d9f79


Appreciate your Kudos.


Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.