Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find total duration of time in power bi?

I have time format in text as a table in Power bi.

Table

I want to find total duration of time by adding all time together in days, hours, minutes, seconds Something like this:-

Result

How can I write Dax for this?

Thanks in advance!!

like image 405
Aditya Ranjan Avatar asked Sep 17 '25 07:09

Aditya Ranjan


2 Answers

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

like image 171
Aditya Ranjan Avatar answered Sep 19 '25 15:09

Aditya Ranjan


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-

enter image description here

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"
like image 23
mkRabbani Avatar answered Sep 19 '25 14:09

mkRabbani