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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MarkianLC
New Member

Sorting on X axis on created column

Hello,

Am in need of assistance....I have a query returning "Elapsed minutes" as Whole Number data type. I created a new column, within PowerBI, which "categorizes" the value into "buckets of time". This created column is set up as: 

Time_Slot =
IF(Mobile_Visit_Detail[Elapsed Time]< 10,"0-10",
IF(Mobile_Visit_Detail[Elapsed Time]>=10&&Mobile_Visit_Detail[Elapsed Time]<=15,"10-15",
IF(Mobile_Visit_Detail[Elapsed Time]>15&&Mobile_Visit_Detail[Elapsed Time]<=30,"15-30",
IF(Mobile_Visit_Detail[Elapsed Time]>30&&Mobile_Visit_Detail[Elapsed Time]<=60,"30-60",
IF(Mobile_Visit_Detail[Elapsed Time]>60&&Mobile_Visit_Detail[Elapsed Time]<=180,"60-180",
IF(Mobile_Visit_Detail[Elapsed Time]>180&&Mobile_Visit_Detail[Elapsed Time]<=360,"180-360",
IF(Mobile_Visit_Detail[Elapsed Time]>360&&Mobile_Visit_Detail[Elapsed Time]<=540,"360-540",
IF(Mobile_Visit_Detail[Elapsed Time]>540&&Mobile_Visit_Detail[Elapsed Time]<=720,"540-720",
"720 +"))))))))
 
No matter which chart visual I use, I cannot get the sorting/ordering of the X axis (using the Time_Slot column) to sort in the ascedning "number of minutes" categories......Left to right should be:
0-10
10-15
15-30
30-60
60-180
180-360
360-540
540-720
720+
The visual displays in this order:
0-10, 10-15, 15-30, 180-360, 30-60, 60-180, 720+ 
There are two categories which have no counts. (Not displaying these two is not a problem, but an annoyance for me. Even if checking "Show items with no data", they don't display).
The Time_Slot column is  Data type of text. Changing it to whole number, or any other type doesn't work b/c of the dashes and the "+" in the 720+.
 
What do I need to do to get this visual to display in Time_Slot ascending order with their corresponding values.
 
Here's what the visual looks like now:
 
MarkianLC_0-1663350888749.png

 

 
1 ACCEPTED SOLUTION

Did you set the TimeSlot column to be sorted by the ID column?

lbendlin_0-1663608242617.png

 

View solution in original post

8 REPLIES 8
lbendlin
Super User
Super User

First thing to do is create a reference table with your desired buckets and another column indicating the sort order. 

lbendlin_0-1663437713338.png

 

Then you can sort the bucket name by the bucket ID

 

Note:  You can slightly simplify your formula

Time_Slot = SWITCH(TRUE()
,Mobile_Visit_Detail[Elapsed Time]<=10,"0-10"
,Mobile_Visit_Detail[Elapsed Time]<=15,"10-15"
,Mobile_Visit_Detail[Elapsed Time]<=30,"15-30"
,Mobile_Visit_Detail[Elapsed Time]<=60,"30-60"
,Mobile_Visit_Detail[Elapsed Time]<=180,"60-180"
,Mobile_Visit_Detail[Elapsed Time]<=360,"180-360"
,Mobile_Visit_Detail[Elapsed Time]<=540,"360-540"
,Mobile_Visit_Detail[Elapsed Time]<=720,"540-720"
,"720 +")

 

 

Thank you. However, the sorting is still not as intended.

I created the table as such:

MVTimeSlots = {
(1,"0-10", 1)
,(2,"10-15",2)
,(3,"15-30",3)
,(4,"30-60",4)
,(5,"60-180",5)
,(6,"180-360",6)
,(7,"360-540",7)
,(8,"540-720",8)
,(9,"720 +",9)
}
................................
Then, made the relationship from the "data" table to the created table.
The updated visual is still displaying incorrectly. The visual's axis field has the "TimeSlot" and "Order" columns from the created table MVTimeSlots.
Not able to sort the Axis by "Order".
Am using PowerBI Report Server version Version: 2.100.1381.0 64-bit (January 2022).
 
Here's the visual:
MarkianLC_0-1663595999134.png

 

 

 

You now need to put the text from the reference table into the X axis, not from the data table.

 

see attached for a simplified version.

The reference table is "MVTimeSlots" with column "TimeSlot". It is on the Axis.

The Values is from the data table: "Count of Time_Slot". 

 

check that your visual is actually sorted by the X axis field.

It looks to be sorted by the X axis.

MarkianLC_0-1663607955322.png

 

 

Did you set the TimeSlot column to be sorted by the ID column?

lbendlin_0-1663608242617.png

 

WOW...that was it!

Thank you @lbendlin !

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.