Forum Discussion
Sorting problem with Text Field - mins, days, hrs
- 1 year ago
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 ResultDoes something like this work for you?
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
Does something like this work for you?
It worked. Very Cool!! I have never used dynamic formatting before. Thank you so much 🙂