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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ArchStanton
Impactful Individual
Impactful Individual

Date Bandings require sorting in visual

Hi,

 

I have various date bands ranging from 0-3mths, 3-6 and so on all the way up to 12 mths +.

These are not sorted when I add them to the Y axis in my visual so I was thinking of ranking them 1 to 5 and then sorting them that way. Is this the best method to do thi?

 

I thought I could write a NESTEDIF Statement but it isn't working:

 

RANK = IF([Age Profile Creation Months] = "0-3 Months",1, IF([Age Profile Creation Months] = "3-6 Months",2, IF([Age Profile Creation Months] = "6-9 Months",3,IF([Age Profile Creation Months] = "9-12 Months",4, IF([Age Profile Creation Months] = "12+ Months",5, "")))))
 
Any ideas anyone?
Thanks
1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @ArchStanton ,

Pls test the below:

RANK = 
IF (
    [Age Profile Creation Months] = "0-3 Months",
    1,
    IF (
        [Age Profile Creation Months] = "3-6 Months",
        2,
        IF (
            [Age Profile Creation Months] = "6-9 Months",
            3,
            IF (
                [Age Profile Creation Months] = "9-12 Months",
                4,
                IF ( [Age Profile Creation Months] = "12+ Months", 5,BLANK() )
            )
        )
    )
)

Return:

vluwangmsft_0-1664786668403.png

 

 

Best Regards

Lucien

 

View solution in original post

12 REPLIES 12
v-luwang-msft
Community Support
Community Support

Hi @ArchStanton ,

Pls test the below:

RANK = 
IF (
    [Age Profile Creation Months] = "0-3 Months",
    1,
    IF (
        [Age Profile Creation Months] = "3-6 Months",
        2,
        IF (
            [Age Profile Creation Months] = "6-9 Months",
            3,
            IF (
                [Age Profile Creation Months] = "9-12 Months",
                4,
                IF ( [Age Profile Creation Months] = "12+ Months", 5,BLANK() )
            )
        )
    )
)

Return:

vluwangmsft_0-1664786668403.png

 

 

Best Regards

Lucien

 

ArchStanton
Impactful Individual
Impactful Individual

This is my other attempt based directly on what you suggested

 

ArchStanton_0-1664544638999.png

 

replace the "N/A" with 6. You can't return an integer and a string into the same column.

ArchStanton
Impactful Individual
Impactful Individual

It still has the same error when N/a is replace with 6

 

ArchStanton_0-1664545376639.png

 

that's still a string, you need to return the number 6 without the quotes

ArchStanton
Impactful Individual
Impactful Individual

 

I've tried lots of variations and the error just keeps appearing:

 

ArchStanton_0-1664546265915.png

 

the switch statement should not have any = signs in it. the first argument should be the column name, then a list of pairs of values separated by commas, see my original post for the template.

ArchStanton
Impactful Individual
Impactful Individual

Thanks, I managed to get it to work but its only given my 5's and 6's for some reason?

 

ArchStanton_0-1664548565508.png

 

In the meantime I've copied the original Date Banding Column - modified it by substituting Date Bands for No's 1-5 and then applied a Sort on the column and this seems to have done the trick. I'd still like to know why the SWITCH code is ignoring 1,2,3,4 though?

the strings would need to match exactly - same capitalization of letters, same number of spaces etc.

ArchStanton_1-1664548829206.png

 

johnt75
Super User
Super User

You could add a column like

Group sort column =
SWITCH (
    'Table'[Age Profile Creation Months],
    "0-3 months", 1,
    "3-6 months", 2
)
ArchStanton
Impactful Individual
Impactful Individual

Thanks but something isn't working right with my code:

 

ArchStanton_0-1664544407312.png

 

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.