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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
TomJWhite
Frequent Visitor

Find date with longest total duration sum (plus how to display decimal hours as hh:mm:ss)

Hi there,

 

I am using a dataset of netflix viewing activity which has a column for [Start Time] e.g '12/30/2020 11:47:48 AM' and a column for [Duration] eg '00:14:58' (hh:mm:ss). Each entry is a viewing, with multiple viewings per day usually. Example below.

 

TitleDurationStart TimeTotal Hours
The Big Bang Theory: Season 6: The Date Night Variable (Episode 1)00:14:5812/30/2020 11:47:48 AM0.25
Bridgerton: Season 1: Diamond of the First Water (Episode 1)   00:54:5812/31/2020 1:30:34 PM 0.92
Bridgerton: Season 1: Shock and Delight (Episode 2)  00:22:1612/31/2020 2:29:20 PM0.37

 

I want to add a card visual showing 'Biggest Viewing Day' which would show the specific date with the highest total sum of [Duration] for entries on that day. Ideally something like "1 Hours 17 Minutes 14 Seconds - January 1st 2020"

 

I have already made another custom column for [Total Hours] which converts a given [Duration] entry to '0.25' etc which seems to work for making column charts for Total Hours by Year etc but I dont know how to go about calculating the sum of duration for each date in the dataset. I also ideally want to have cards for 'Total Hours' but that currently shows like '3,709.03' instead of in hours, minutes, seconds. 

 

Apologies if this is confusing, let me know if I need to clarify anything. 

2 ACCEPTED SOLUTIONS
DataInsights
Super User
Super User

@TomJWhite,

 

Try this solution. It displays the result in hours, but you can format that as "hh:mm:ss" with the help of the article below.

 

https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486 

 

1. Create a calculated column for Start Date. You can do this in Power Query or DAX. Here's the DAX:

 

Start Date = INT ( Table1[Start Time] )

 

2. Create measures:

 

Sum Total Hours = SUM ( Table1[Total Hours] )

Biggest Viewing Day =
VAR vBaseTable =
    ADDCOLUMNS ( VALUES ( Table1[Start Date] ), "@Hours", [Sum Total Hours] )
VAR vRankTable =
    ADDCOLUMNS ( vBaseTable, "@Rank", RANKX ( vBaseTable, [@Hours],, DESC, DENSE ) )
VAR vTopRank =
    FILTER ( vRankTable, [@Rank] = 1 )
VAR vTopHours =
    MAXX ( vTopRank, [@Hours] )
VAR vTopDate =
    MAXX ( vTopRank, Table1[Start Date] )
VAR vResult =
    vTopHours & " - "
        & FORMAT ( vTopDate, "mmmm d, yyyy" )
RETURN
    vResult

 

3. Result:

 

DataInsights_0-1628776016741.png

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Anonymous
Not applicable

Hi  @TomJWhite ,

Here are the steps you can follow:

1. Create calculated column.

Date =
DATE(YEAR('Table'[Start Time]),MONTH('Table'[Start Time]),DAY('Table'[Start Time]))
Duration_add =
SUMX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),[Duration])

2. Create measure.

Measure =
var _max=
MAXX(FILTER(ALL('Table'),'Table'[Duration_add]=MAX('Table'[Duration_add])),[Duration_add])
var _maxdate=
MAXX(FILTER(ALLSELECTED('Table'),'Table'[Duration_add]=_max),[Date])
return
HOUR(_max)&" Hours "&MINUTE(_max)&" Minutes "&SECOND(_max)&" Seconds - "&FORMAT(_maxdate,"mmmm")&" "&DAY(_maxdate)&"st "&YEAR(_maxdate)

3. Result:

vyangliumsft_0-1628840885848.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @TomJWhite ,

Here are the steps you can follow:

1. Create calculated column.

Date =
DATE(YEAR('Table'[Start Time]),MONTH('Table'[Start Time]),DAY('Table'[Start Time]))
Duration_add =
SUMX(FILTER('Table','Table'[Date]=EARLIER('Table'[Date])),[Duration])

2. Create measure.

Measure =
var _max=
MAXX(FILTER(ALL('Table'),'Table'[Duration_add]=MAX('Table'[Duration_add])),[Duration_add])
var _maxdate=
MAXX(FILTER(ALLSELECTED('Table'),'Table'[Duration_add]=_max),[Date])
return
HOUR(_max)&" Hours "&MINUTE(_max)&" Minutes "&SECOND(_max)&" Seconds - "&FORMAT(_maxdate,"mmmm")&" "&DAY(_maxdate)&"st "&YEAR(_maxdate)

3. Result:

vyangliumsft_0-1628840885848.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

DataInsights
Super User
Super User

@TomJWhite,

 

Try this solution. It displays the result in hours, but you can format that as "hh:mm:ss" with the help of the article below.

 

https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486 

 

1. Create a calculated column for Start Date. You can do this in Power Query or DAX. Here's the DAX:

 

Start Date = INT ( Table1[Start Time] )

 

2. Create measures:

 

Sum Total Hours = SUM ( Table1[Total Hours] )

Biggest Viewing Day =
VAR vBaseTable =
    ADDCOLUMNS ( VALUES ( Table1[Start Date] ), "@Hours", [Sum Total Hours] )
VAR vRankTable =
    ADDCOLUMNS ( vBaseTable, "@Rank", RANKX ( vBaseTable, [@Hours],, DESC, DENSE ) )
VAR vTopRank =
    FILTER ( vRankTable, [@Rank] = 1 )
VAR vTopHours =
    MAXX ( vTopRank, [@Hours] )
VAR vTopDate =
    MAXX ( vTopRank, Table1[Start Date] )
VAR vResult =
    vTopHours & " - "
        & FORMAT ( vTopDate, "mmmm d, yyyy" )
RETURN
    vResult

 

3. Result:

 

DataInsights_0-1628776016741.png

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.