Forum Discussion
Calculated column to group rows
- 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
Not sure about how the groupings should work, I created a new column to get the difference in Minuits. Please provide an extended example:
Group =
VAR __CURRENTLOGIN = Table6[LoginTime]
VAR __PREVIOUSLOGIN =
CALCULATE(
MAX( Table6[LogoffTime] ),
ALLEXCEPT(Table6 , Table6[Name] ),
Table6[LoginTime] < __CURRENTLOGIN
)
RETURN
DATEDIFF(__PREVIOUSLOGIN , __CURRENTLOGIN, MINUTE )
- Anonymous4 years agoNot applicable
Thanks for your response. The context is that the duration between the login times are used to charge the user.
If the time between two sessions (row) is less than 20 minutes, the two session will count as one and the total duration of both session will be summed up. So for example looking at just the first 2 rows:
- the user logs on to the workstation from 2:07:57 am to 2:12:13 pm
- then the same user logs on again from 2:12:19 am to 5:50:28 pm
- The user will be charged for a duration of 6h 45 mins.
Thus, I would need a table where I can group the rows that are considered the same logon sessions together and sum up their durations.
Any help would be appreciated. Thanks 😀
- Fowmy4 years agoSuper User
Anonymous
Not quite clear, could you show the calculation In Excel and attach the file using Google or One Drive link here?- Anonymous4 years agoNot applicable
This would be the desired outcome: