Forum Discussion
Anonymous
6 years agoNot applicable
Calculate unique viewership duration
hi, I have that captures viership of media/video content like netflix shown in table below. Row 1 captures viewership of customer "123456" watching video "Short Movie 2" that is 240 secs in durat...
v-juanli-msft
Community Support
6 years agoHi Anonymous
Create a date table
Date1 = ADDCOLUMNS(CALENDARAUTO(),"year-month",FORMAT([Date],"yyyy-mm"))
Add column in Table5,
month = FORMAT([Date],"yyyy-mm")
Measures
s_Min =
CALCULATE (
MIN ( 'Table 5'[Start Index (secs)] ),
FILTER (
ALLSELECTED ( 'Table 5' ),
'Table 5'[Customer ID] = MAX ( 'Table 5'[Customer ID] )
&& 'Table 5'[Video Name] = MAX ( 'Table 5'[Video Name] )
&& 'Table 5'[month] = MAX ( 'Table 5'[month] )
)
)
s_Max =
CALCULATE (
MAX ( 'Table 5'[Start Index (secs)] ),
FILTER (
ALLSELECTED ( 'Table 5' ),
'Table 5'[Customer ID] = MAX ( 'Table 5'[Customer ID] )
&& 'Table 5'[Video Name] = MAX ( 'Table 5'[Video Name] )
&& 'Table 5'[month] = MAX ( 'Table 5'[month] )
)
)
e_Min =
CALCULATE (
MIN ( 'Table 5'[Stop Index (secs)] ),
FILTER (
ALLSELECTED ( 'Table 5' ),
'Table 5'[Customer ID] = MAX ( 'Table 5'[Customer ID] )
&& 'Table 5'[Video Name] = MAX ( 'Table 5'[Video Name] )
&& 'Table 5'[month] = MAX ( 'Table 5'[month] )
)
)
e_Max =
CALCULATE (
MAX ( 'Table 5'[Stop Index (secs)] ),
FILTER (
ALLSELECTED ( 'Table 5' ),
'Table 5'[Customer ID] = MAX ( 'Table 5'[Customer ID] )
&& 'Table 5'[Video Name] = MAX ( 'Table 5'[Video Name] )
&& 'Table 5'[month] = MAX ( 'Table 5'[month] )
)
)
sec total = IF([s_Max]<=[e_Min],[e_Max]-[s_Min],[e_Min]-[s_Min]+[e_Max]-[s_Max])
duration_f =
IF (
[sec total] <> BLANK (),
IF (
[s_Max] <= [e_Min],
[s_Min] & "-" & [e_Max],
[s_Min] & "-" & [e_Min] & "," & [s_Max] & "-" & [e_Max]
)
)
Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
6 years agoNot applicable
Hi v-juanli-msft Maggie
I believe this is the closest to the final solution. Absolutely Brilliant. However, I believe, the formula fails for the following scenario
| Customer ID | Date | Movie | StartIndex | StopIndex |
| 123456 | aug 20 | short movie3 | 20 | 40 |
| 123456 | aug 20 | short movie3 | 30 | 50 |
| 123456 | aug 20 | short movie3 | 60 | 80 |
| 123456 | aug 20 | short movie3 | 90 | 100 |
in this case [sec_total] = 30. But actual unique duration for the month of august = 60. It misses out row 3 & 4.
Any thoughts on this?