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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
crispybc
Frequent Visitor

Preview Feature Dynamic Formatting (time duration format)

I have seen the new preview feature for dynamic formatting and though I'd give it a go formating a duration measure (hours) into the format years,days,hours using the following formatting dax:

 

var col = [last status change duration]
var totaldays =  QUOTIENT(col,24)
var years = if (totaldays > 365, CONCATENATE(CONVERT(ROUNDDOWN(DIVIDE(totaldays,365),0),STRING),"y"))
var days = IF(MOD(totaldays, 365) >=1 , CONCATENATE(CONVERT(ROUNDDOWN(MOD(totaldays, 365),0),STRING),"d"))
var hours = if (MOD(col, 24) >=1, CONCATENATE(convert(TRUNC(MOD(col, 24)),STRING),"h"))
var string =  COMBINEVALUES(" ",years , days, hours)
return string

 

 

However, this is sometime returning incorrect values.

 

crispybc_0-1681827278196.png

Not sure if i am doing something wrong, or it is just a bug with the new feature. Has anyone else managed to format a time duration measure into an easily readable format?

1 ACCEPTED SOLUTION
crispybc
Frequent Visitor

I figured out the issue. If your output string contains a 0, then it is substituted out for the measure value. 

You can work around this with the SUBSTITUTE function.

 

So new solution:

var col = [last status change duration]
var totaldays =  ROUNDDOWN(DIVIDE(col,24),0)
var years = if (totaldays > 365, CONCATENATE(CONVERT(ROUNDDOWN(DIVIDE(totaldays,365),0),STRING),"y"))
var days = IF(MOD(totaldays, 365) >=1 , CONCATENATE(CONVERT(ROUNDDOWN(MOD(totaldays, 365),0),STRING),"d"))
var hours = if (MOD(col, 24) >=1, CONCATENATE(convert(TRUNC(MOD(col, 24)),STRING),"h"))
var string =  COMBINEVALUES(" ",years , days, hours)
return SUBSTITUTE(string, "0", "\0")

 

View solution in original post

1 REPLY 1
crispybc
Frequent Visitor

I figured out the issue. If your output string contains a 0, then it is substituted out for the measure value. 

You can work around this with the SUBSTITUTE function.

 

So new solution:

var col = [last status change duration]
var totaldays =  ROUNDDOWN(DIVIDE(col,24),0)
var years = if (totaldays > 365, CONCATENATE(CONVERT(ROUNDDOWN(DIVIDE(totaldays,365),0),STRING),"y"))
var days = IF(MOD(totaldays, 365) >=1 , CONCATENATE(CONVERT(ROUNDDOWN(MOD(totaldays, 365),0),STRING),"d"))
var hours = if (MOD(col, 24) >=1, CONCATENATE(convert(TRUNC(MOD(col, 24)),STRING),"h"))
var string =  COMBINEVALUES(" ",years , days, hours)
return SUBSTITUTE(string, "0", "\0")

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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