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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ArchStanton
Impactful Individual
Impactful Individual

Switch Function Not Working

Hi,

 

The following code only brings back the ELSE parameter 9, I can't work out why?

 

RANK2 Sort = SWITCH(
            TRUE(),
                'Cases'[Age Profile2] = "0-3 Mths",1,
                'Cases'[Age Profile2] = "3-6 Mths",2,
                'Cases'[Age Profile2] = "6-9 Mths",3,
                'Cases'[Age Profile2] = "9-12 Mths",4,
                'Cases'[Age Profile2] = "12-15 Mths",5,
                'Cases'[Age Profile2] = "15-18 Mths",6,
                'Cases'[Age Profile2] = "18-21 Mths",7,
                'Cases'[Age Profile2] = "21-24 Mths",8,
                9)
                
       

 

The Age Profile Column my Sort Column is referencing is here:

 

Age Profile2 = 
if( 'Cases'[Case Length (Validation Date)] < 90.25 , " 0-3 Mths",
    if('Cases'[Case Length (Validation Date)] < 182.5, " 3-6 Mths",
        if('Cases'[Case Length (Validation Date)] < 273.75, " 6-9 Mths", 
            if('Cases'[Case Length (Validation Date)] < 365.25, " 9-12 Mths", 
                if('Cases'[Case Length (Validation Date)] < 456.25, " 12-15 Mths",
                   if('Cases'[Case Length (Validation Date)] < 547.5, " 15-18 Mths", 
                      if('Cases'[Case Length (Validation Date)] < 638.75, " 18-21 Mths", 
                         if('Cases'[Case Length (Validation Date)] < 730, " 21-24 Mths",
                         "24+ Mths"))))))))

 

Any ideas why this is going wrong?

Thanks

1 ACCEPTED SOLUTION
MAwwad
Solution Sage
Solution Sage

Hello,

 

 

Try to copy paste the same value exactly as SWITCH Is case sensitive, I see some spaces in your values 

example : 

" 0-3 Mths"

 

While in your switch function: 

"0-3 Mths"

 

So I dont think its considering them the same values.

 

 

Please accept this as a solution if it helped you 🙂

View solution in original post

2 REPLIES 2
MAwwad
Solution Sage
Solution Sage

Hello,

 

 

Try to copy paste the same value exactly as SWITCH Is case sensitive, I see some spaces in your values 

example : 

" 0-3 Mths"

 

While in your switch function: 

"0-3 Mths"

 

So I dont think its considering them the same values.

 

 

Please accept this as a solution if it helped you 🙂

ArchStanton
Impactful Individual
Impactful Individual

Yes, thanks, the answer was starring me in the face!

Much appreciated!!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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