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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
AmberJane
Helper III
Helper III

Sorting problem with Text Field - mins, days, hrs

I have a measure that is taking a whole number for the dataset representing minutes and converting it to mins, days, hrs. This measure is a text column and as such when I try to filter it is not filtering the way I would like. Smallest to largest should always be mins > hrs > days. This is how it is currently sorting: 

 

AmberJane_0-1737391894302.png

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @AmberJane 

I would suggest creating a measure with a dynamic format string for this, so that the measure is still evaluated as a numerical value (which can be sorted), but displayed with the appropriate formatting.

 

You would have to use a format string that produces the full text you want displayed enclosed in double quotes, conditional on the value (in minutes).

 

I've attached a small example showing how you could do this.

The important part is 3rd piece of code below which is the expression for the dynamic format string.

You could also use the expression you have already created for SLA Impact Converted, as long you enclose the result in double quotes similarly to below.

SLA Impact = 
-- Underlying measure returning value in Minutes
SUM ( 'Table'[Duration mins] )
SLA Impact Converted = 
[SLA Impact]
-- FORMAT STRING for SLA Impact Converted
VAR NumberFormatString = "0.0#" -- change as required
VAR MinsPerDay = 24 * 60
VAR MinsPerHour = 60
VAR DoubleQuote = """"
VAR MeasureValue = SELECTEDMEASURE ()
VAR FormattedValue =
    SWITCH (
        TRUE (),
        MeasureValue >= MinsPerDay, FORMAT ( MeasureValue / MinsPerDay, NumberFormatString ) & " Days",
        MeasureValue >= MinsPerHour, FORMAT ( MeasureValue / MinsPerHour, NumberFormatString ) & " Hrs",
        FORMAT ( MeasureValue, NumberFormatString ) & " Mins"
    )
VAR Result =
    DoubleQuote & FormattedValue & DoubleQuote
RETURN
    Result

 

OwenAuger_0-1737414831226.png

Does something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @AmberJane ,

Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
OwenAuger
Super User
Super User

Hi @AmberJane 

I would suggest creating a measure with a dynamic format string for this, so that the measure is still evaluated as a numerical value (which can be sorted), but displayed with the appropriate formatting.

 

You would have to use a format string that produces the full text you want displayed enclosed in double quotes, conditional on the value (in minutes).

 

I've attached a small example showing how you could do this.

The important part is 3rd piece of code below which is the expression for the dynamic format string.

You could also use the expression you have already created for SLA Impact Converted, as long you enclose the result in double quotes similarly to below.

SLA Impact = 
-- Underlying measure returning value in Minutes
SUM ( 'Table'[Duration mins] )
SLA Impact Converted = 
[SLA Impact]
-- FORMAT STRING for SLA Impact Converted
VAR NumberFormatString = "0.0#" -- change as required
VAR MinsPerDay = 24 * 60
VAR MinsPerHour = 60
VAR DoubleQuote = """"
VAR MeasureValue = SELECTEDMEASURE ()
VAR FormattedValue =
    SWITCH (
        TRUE (),
        MeasureValue >= MinsPerDay, FORMAT ( MeasureValue / MinsPerDay, NumberFormatString ) & " Days",
        MeasureValue >= MinsPerHour, FORMAT ( MeasureValue / MinsPerHour, NumberFormatString ) & " Hrs",
        FORMAT ( MeasureValue, NumberFormatString ) & " Mins"
    )
VAR Result =
    DoubleQuote & FormattedValue & DoubleQuote
RETURN
    Result

 

OwenAuger_0-1737414831226.png

Does something like this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

It worked. Very Cool!! I have never used dynamic formatting before. Thank you so much 🙂 

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! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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