I have time format in text as a table in Power bi.
I want to find total duration of time by adding all time together in days, hours, minutes, seconds Something like this:-
How can I write Dax for this?
Thanks in advance!!
total_duration_dax_2 =
var total_second =
SUMX(
TIME2,
INT(
VALUE(LEFT(TIME2[Table2],2))
)
) * 60 * 60
+
SUMX(
TIME2,
INT(
VALUE(MID(TIME2[Table2],4,2))
)
) * 60
+
SUMX(
TIME2,
INT(
VALUE(RIGHT(TIME2[Table2],2))
)
)
var DayCount = INT(total_second/(24*60*60))
var HoursCount = MOD(INT(total_second/(60*60)),24)
var MinCount = MOD(INT(total_second/60),60)
var SecCount = MOD(total_second,60)
RETURN DayCount & " Days & " & HoursCount & " Hours & " & MinCount & " Minutes & " & SecCount & " Seconds"
The result is same
Although you already excepted my first answer, I wants to let you know about another option. I am posting it as separate answer as I do not wants to mess between two answer.
You can also do the whole thing using DAX without steps I have explained in my earlier answer. You can do it directly from list of value like-
The DAX query is(bit big but you can make a try)-
total_seconds_dax =
var total_second =
SUMX(
total_time,
INT(
MID(
total_time[Time],
1,
SEARCH(":",total_time[Time],1,0) - 1
)
)
) * 60 * 60
+
SUMX(
total_time,
INT(
MID(
total_time[Time],
SEARCH(":",total_time[Time],1,0) + 1,
SEARCH(
":",
total_time[Time],
SEARCH(":",total_time[Time],1,0) + 1
,0
)
-
(SEARCH(":",total_time[Time],1,0) + 1)
)
)
) * 60
+
SUMX(
total_time,
INT(
MID(
total_time[Time],
SEARCH(
":",
total_time[Time],
SEARCH(":",total_time[Time],1,0) + 1
,0
) + 1
,
LEN(total_time[Time]) -
SEARCH(
":",
total_time[Time],
SEARCH(":",total_time[Time],1,0) + 1
,0
)
)
)
)
var DayCount = INT(total_second/(24*60*60))
var HoursCount = MOD(INT(total_second/(60*60)),24)
var MinCount = MOD(INT(total_second/60),60)
var SecCount = MOD(total_second,60)
RETURN DayCount & " Days & " & HoursCount & " Hours & " & MinCount & " Minutes & " & SecCount & " Seconds"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With