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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
am_i_really
Frequent Visitor

Showing Time range in order

Hi All, I'm having an issue with getting my data to sort correctly. I have the following switch statement I used to group the data into time ranges but it does not show in correct order. It wont allow me to sort the column either

 

 

TimeGroup = SWITCH(
    TRUE(),
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(00,00,00), SF_YTD_Master[ORDER_TIME] < TIME(03,00,00)), "12-3 am",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(03,00,00), SF_YTD_Master[ORDER_TIME] < TIME(06,00,00)), "3-6 am",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(06,00,00), SF_YTD_Master[ORDER_TIME] < TIME(09,00,00)), "6-9 am",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(09,00,00), SF_YTD_Master[ORDER_TIME] < TIME(12,00,00)), "9-12 pm",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(12,00,00), SF_YTD_Master[ORDER_TIME] < TIME(15,00,00)), "12-3 pm",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(15,00,00), SF_YTD_Master[ORDER_TIME] < TIME(18,00,00)), "3-6 pm",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(18,00,00), SF_YTD_Master[ORDER_TIME] < TIME(21,00,00)), "6-9 pm",
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(21,00,00), SF_YTD_Master[ORDER_TIME] <= TIME(23,59,59)), "9-12 am"
)

 

am_i_really_0-1689016551421.png

Thanks in advance!

1 ACCEPTED SOLUTION
Arul
Super User
Super User

@am_i_really ,

You have sort this column at model level. Try the below code to create a calculated column and then use sort by column option at model level,

TimeGroup Sort = SWITCH(
    TRUE(),
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(00,00,00), SF_YTD_Master[ORDER_TIME] < TIME(03,00,00)), 1,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(03,00,00), SF_YTD_Master[ORDER_TIME] < TIME(06,00,00)), 2,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(06,00,00), SF_YTD_Master[ORDER_TIME] < TIME(09,00,00)), 3,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(09,00,00), SF_YTD_Master[ORDER_TIME] < TIME(12,00,00)), 4,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(12,00,00), SF_YTD_Master[ORDER_TIME] < TIME(15,00,00)), 5,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(15,00,00), SF_YTD_Master[ORDER_TIME] < TIME(18,00,00)), 6,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(18,00,00), SF_YTD_Master[ORDER_TIME] < TIME(21,00,00)), 7,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(21,00,00), SF_YTD_Master[ORDER_TIME] <= TIME(23,59,59)), 8
)

Then select the time group column and then use time group sort in sort by column option,

Arul_0-1689047981490.png

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


View solution in original post

2 REPLIES 2
am_i_really
Frequent Visitor

That worked, thank you!

Arul
Super User
Super User

@am_i_really ,

You have sort this column at model level. Try the below code to create a calculated column and then use sort by column option at model level,

TimeGroup Sort = SWITCH(
    TRUE(),
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(00,00,00), SF_YTD_Master[ORDER_TIME] < TIME(03,00,00)), 1,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(03,00,00), SF_YTD_Master[ORDER_TIME] < TIME(06,00,00)), 2,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(06,00,00), SF_YTD_Master[ORDER_TIME] < TIME(09,00,00)), 3,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(09,00,00), SF_YTD_Master[ORDER_TIME] < TIME(12,00,00)), 4,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(12,00,00), SF_YTD_Master[ORDER_TIME] < TIME(15,00,00)), 5,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(15,00,00), SF_YTD_Master[ORDER_TIME] < TIME(18,00,00)), 6,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(18,00,00), SF_YTD_Master[ORDER_TIME] < TIME(21,00,00)), 7,
    AND(SF_YTD_Master[ORDER_TIME] >= TIME(21,00,00), SF_YTD_Master[ORDER_TIME] <= TIME(23,59,59)), 8
)

Then select the time group column and then use time group sort in sort by column option,

Arul_0-1689047981490.png

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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