Forum Discussion
Anonymous
4 years agoNot applicable
Calculated column to group rows
I have a calculated table with the following fields representing log in sessions. Im trying to group the rows together if: They have the same name ie PR The time between the previous lo...
- 4 years ago
Hi Anonymous ,
According to your description, here's my solution, I create four measures.
Mins Between Logoff (mins) = IF ( MAX ( 'Table'[Rank] ) = 1, "", CALCULATE ( DATEDIFF ( MAXX ( FILTER ( ALL ( 'Table' ), 'Table'[Rank] = MAX ( 'Table'[Rank] ) - 1 && 'Table'[Name] = MAX ( 'Table'[Name] ) ), 'Table'[LogoffTime] ), MAX ( 'Table'[LoginTime] ), MINUTE ) ) )Duration (mins) = DATEDIFF(MAX('Table'[LoginTime]),MAX('Table'[LogoffTime]),MINUTE)SessionID = CALCULATE ( COUNT ( 'Table'[Name] ), FILTER ( ALL ( 'Table' ), 'Table'[Name] = MAX ( 'Table'[Name] ) && [Mins Between Logoff (mins)] >= 20 && 'Table'[Rank] <= MAX ( 'Table'[Rank] ) ) )Total Duration per session (mins) = VAR _Add = ADDCOLUMNS ( ALL ( 'Table' ), "sessionID", [SessionID] ) VAR _Add2 = ADDCOLUMNS ( _Add, "Duration", SUMX ( FILTER ( _Add, [Name] = EARLIER ( [Name] ) && [sessionID] = EARLIER ( [sessionID] ) ), [Duration (mins)] ) ) RETURN SUMX ( FILTER ( _Add2, [Name] = MAX ( 'Table'[Name] ) && [Rank] = MAX ( 'Table'[Rank] ) ), [Duration] )Get the expected result.
I attach my sample below to help you understanding.
Best Regards,
Community Support Team _ kalyjIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
4 years agoNot applicable
Thank you so much for this.
One question I have for SessionID, why is max used in the filter. Does the max take the row value that im evaluating ie 1 value only?
SessionID =
CALCULATE (
COUNT ( 'Table'[Name] ),
FILTER (
ALL ( 'Table' ),
'Table'[Name] = MAX ( 'Table'[Name] )
&& [Mins Between Logoff (mins)] >= 20
&& 'Table'[Rank] <= MAX ( 'Table'[Rank] )
)
)
v-yanjiang-msft
4 years agoCommunity Support
Hi Anonymous ,
MAX be used in a measure can return the current value at the same row in a visual.
Best Regards,
Community Support Team _ kalyj