Forum Discussion
Calculate unique viewership duration
Hi 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.
- lbendlin6 years ago
Super User
I thought about it some more and here is what I would do:
For each customer and video collect all the viewed seconds ( via GENERATESERIES ) into a table variable and then do a DISTINCTCOUNT on the second values. That has the same effect as EXCEPT but across all video fragments.
- Anonymous6 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?