Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi everyone
I was asked to get a number of user stays active in an app per day and length in each session.
The system is designed in a way that once user logins, a session automatically refresh every 2 minutes until session expires. There is Log Out but rarely happens. In that case, there is a need to derive data with 2 minute accuracy from the time user login.
Here is the current table available
Login DateTime | User |
7/May/2020 10.15am | 1 |
7/May/2020 10.17am | 1 |
7/May/2020 10.18am | 2 |
7/May/2020 10.19am | 1 |
7/May/2020 10.20am | 2 |
7/May/2020 5.12pm | 1 |
7/May/2020 5.14pm | 1 |
7/May/2020 7.20pm | 1 |
7/May/2020 7.22pm | 1 |
7/May/2020 7.23pm | 3 |
7/May/2020 7.24pm | 1 |
And desire outcome is to have 2 additional columns/measures named "Interval" and "Session per Day".
Date | User | Interval | Session per Day |
7-May-20 | 1 | 4-6 mins | 2 |
7-May-20 | 1 | 2-4 mins | 1 |
7-May-20 | 2 | 4-6 mins | 1 |
7-May-20 | 3 | 0-2 mins | 1 |
Appreciate for any help. Thank you so much
Solved! Go to Solution.
@Anonymous You're close, but I would expect your DAX to return almost all LOGIN??
Earlier as used in this expression is enabling us to compare Execution time to the Login Recheck for every single row in the table within the FILTER expression. You need to figure out if that Execution time is within 2 minutes of any other Execution time for the same user, so we'll count all the rows where that condition is true. The below formula works with my sample data, but you'll want to examine it and your data closely and make sure you understand what it's doing, as if your intervals become too close together it could start to have some inconsistencies again.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
I'm halfway there, but haven't got the duration part yet, need to think about @Greg_Deckler 's suggestion of using MAXX to get the duration...
Here's what I have so far:
Create a series of Calculated COLUMNS in the table:
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@AllisonKennedyMaybe we can also detect the logoff step? Does this work? I just reversed the loginrecheck condition in the second comparison:
LogoffStatus2 = IF(COUNTROWS(FILTER(UserLoginTable, EARLIER(UserLoginTable[User])=UserLoginTable[User] && EARLIER(UserLoginTable[LogInRecheck])=UserLoginTable[Login DateTime]))=1, "","Logoff")
@sanimesa sounds like you're getting it to work.
Here's one idea for the interval:
Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos.
I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@AllisonKennedy Your solution is brilliant!. Thank you.
Almost there.. it works if the duration is in exact 2 minutes, however, the interval should be within 2 mins. This is how it looks like in my current data. Those highlighted in yellow is marked as "Login" although it should be blank.
I tried to modify your code to this, but still not giving me the correct result. Any idea what should it be?
@Anonymous You're close, but I would expect your DAX to return almost all LOGIN??
Earlier as used in this expression is enabling us to compare Execution time to the Login Recheck for every single row in the table within the FILTER expression. You need to figure out if that Execution time is within 2 minutes of any other Execution time for the same user, so we'll count all the rows where that condition is true. The below formula works with my sample data, but you'll want to examine it and your data closely and make sure you understand what it's doing, as if your intervals become too close together it could start to have some inconsistencies again.
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
Copying DAX from this post? Click here for a hack to quickly replace it with your own table names
Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C
I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com
@AllisonKennedy you should be able to get the duration/interval using this technique: See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...
Sorry, should have posted that...earlier (bad joke).
Well, haven't looked at this close enough to give you a definitive answer, but it is going to involve EARLIER. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
I think I would start by getting the minutes between a row and the previous row (using MAXX and EARLIER). Then you can go from there to aggregate rows since if if that duration is longer than 2 minutes it is a new session.
That's what I'm thinking.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
144 | |
75 | |
63 | |
51 | |
48 |
User | Count |
---|---|
204 | |
86 | |
64 | |
59 | |
56 |