Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
joschae
New Member

Using an event log to find out who is logged into an application (not powerbi app)

All of my attempts have failed trying to use a log to find out how many licenses are used up for an application. I am typically getting a "Expression.Error: A cyclic reference was encountered during evaluation" error. My goal is to count the logins per user and per app. Users can be logged in over a 24 hour period.


Key note: The users have 4 apps they can log into and they can log into the same app with multple session. The logs will show the new login session, but the syntax is identical outside of the timestamp. My goal is to basically count the app logins greater than the last logout timestamp (per user, per app).

 

User 1loginApp 18/14/2023 8:05
User 1loginApp 18/14/2023 8:00
User 2logoutApp 48/14/2023 7:00
User 3loginApp 38/13/2023 4:01
User 1logoutApp 18/13/2023 17:00
User 3loginApp 28/13/2023 4:00
User 2logoutApp 18/12/2023 6:00
User 2loginApp 48/11/2023 4:00


Any ideas on the best way to accomplish this? Best Regards!

 

1 ACCEPTED SOLUTION

Hi @joschae ,

 

Please try this:

Flag 2 = 
VAR __user = 'Table'[User]
VAR __app = 'Table'[APP]
VAR __last_datetime = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[User]=EARLIER('Table'[User]) && 'Table'[APP]=EARLIER('Table'[APP])&&'Table'[State]="login"))
VAR __result =
    IF (
        'Table'[State] = "login" && 'Table'[DateTime]=__last_datetime
            && CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[User] = __user
                        && 'Table'[APP] = __app
                        && 'Table'[DateTime] < EARLIER ( 'Table'[DateTime] )
                        && 'Table'[State] = "logout"
                )
            ) > 0,
        1
    )
RETURN
    __result

vcgaomsft_0-1692238144711.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

4 REPLIES 4
v-cgao-msft
Community Support
Community Support

Hi @joschae ,

 

Please first create a new calculated column:

Flag = 
VAR __user = 'Table'[User]
VAR __app = 'Table'[APP]
VAR __result =
    IF (
        'Table'[State] = "login"
            && CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[User] = __user
                        && 'Table'[APP] = __app
                        && 'Table'[DateTime] < EARLIER ( 'Table'[DateTime] )
                        && 'Table'[State] = "logout"
                )
            ) > 0,
        1
    )
RETURN
    __result

vcgaomsft_0-1692166350196.png

Then please new a measre:

Total = COUNTROWS(SUMMARIZE(FILTER('Table','Table'[Flag]>0),'Table'[User],'Table'[APP]))

Output is 1.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

It's very close.  The only issue is that every login after a logout is flagged.  Even the ones that are weeks old.  I only need the most recent logins.  Meaning the logins after the last logout.

Hi @joschae ,

 

Please try this:

Flag 2 = 
VAR __user = 'Table'[User]
VAR __app = 'Table'[APP]
VAR __last_datetime = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[User]=EARLIER('Table'[User]) && 'Table'[APP]=EARLIER('Table'[APP])&&'Table'[State]="login"))
VAR __result =
    IF (
        'Table'[State] = "login" && 'Table'[DateTime]=__last_datetime
            && CALCULATE (
                COUNTROWS ( 'Table' ),
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[User] = __user
                        && 'Table'[APP] = __app
                        && 'Table'[DateTime] < EARLIER ( 'Table'[DateTime] )
                        && 'Table'[State] = "logout"
                )
            ) > 0,
        1
    )
RETURN
    __result

vcgaomsft_0-1692238144711.png

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

I think you pretty much nailed it and I understand the concept now.    I had to minor tweak so that all logins where flagged that were post the last logout. However I will accept the solution.   

 

VAR __last_datetime = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[User]=EARLIER('Table'[User]) && 'Table'[APP]=EARLIER('Table'[APP])&&'Table'[State]="login"))

to 

VAR __last_logout_datetime = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[User]=EARLIER('Table'[User]) && 'Table'[APP]=EARLIER('Table'[APP])&&'Table'[State]="logout"))

 

'Table'[DateTime]=__last_datetime

to

'Table'[DateTime]>__last_logout_datetime

 

The reason the original flag did not work is becuase my complete data is more like this. See User 1.

 

User 1loginApp 18/14/2023 8:05
User 1loginApp 18/14/2023 8:00
User 2logoutApp 48/14/2023 7:00
User 3loginApp 38/13/2023 4:01
User 1logoutApp 18/13/2023 17:00
User 3loginApp 28/13/2023 4:00
User 2logoutApp 18/12/2023 6:00
User 2loginApp 48/11/2023 4:00
User 2logoutApp 18/12/2023 6:00
User 2loginApp 48/11/2023 4:00
User 1loginApp 18/10/2023 8:00
User 1logoutApp 18/9/2023 15:00

 

Thank you!  I learned a lot from your expertise

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors