Forum Discussion
Anonymous
5 years agoNot applicable
Create a function in DAX?
I have a table with about 20 measures displaying a number which is the number of seconds. E.g. 19,000 which means 5 hours 16 minutes and 40 seconds. I can edit each measure and add the logic to do th...
AlexisOlson
5 years agoSuper User
Unfortunately, you can't define functions in DAX. (There are some clunky workarounds like defining a parameter table to use as the domain of the function and using filters on that table to pass values into the function but that's not feasible for large domains.)
Fortunately, the code to format is simple. Power BI interprets numbers as durations in days, so you can format N_Seconds in HH:MM:SS as
FORMAT(N_Seconds/60/60/24, "HH:MM:SS")
which isn't much more verbose than calling a separate function anyway.
Another possibility would be to try defining a calculation group where you create a calculation item like this:
FORMAT ( SELECTEDMEASURE()/86400, "HH:MM:SS" )