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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

How to find out most frequent user based on the logged in period

Hi All,

I am looking for an answer to the below question I have while preparing some visuals in Power BI. Appreciate your help and valuable advice on this query.


I have data in a table as below:

 

table.png

 

I need to find out the most frequent and the least frequent user based on the duration they have logged into the device.

 

In this table, the most frequent user for the deviceId=1, would be User C and the least frequent user would be User A.

 

Similarly, the most frequent user for the deviceId=2, would be User Y and the least frequent user would be User X.

 

I am trying to find a way to calculate this in Power BI so that I can prepare some visuals based on that.

 

Thanks in advance for your help!.

2 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

Hi  @Anonymous 

 

try to create two measures with this code:

MaxUser = 
VAR MaxDuration = 
MAXX(
    TableName, 
    TableName[LastSeen] - TableName[FirstSeen]
)
RETURN
CALCULATE(
    VALUES(TableName[User]),
    TableName[LastSeen] - TableName[FirstSeen] = MaxDuration
)

MinUser = 
VAR MinDuration = 
MINX(
    TableName, 
    TableName[LastSeen] - TableName[FirstSeen]
)
RETURN
CALCULATE(
    VALUES(TableName[User]),
    TableName[LastSeen] - TableName[FirstSeen] = MinDuration
)

 

I tried and it worked like this:

FreemanZ_0-1670658314937.png

View solution in original post

v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Column:

Difference = DATEDIFF([firstSeen],[lastSeen],MINUTE)

vzhangti_0-1670810729695.png

Measure:

Max user = 
CALCULATE (
    MAX ( 'Table'[User] ),
    FILTER (
        ALL ( 'Table' ),
        [Difference] = MAX ( 'Table'[Difference] )
            && [deviceID] = SELECTEDVALUE ( 'Table'[deviceID] )
    )
)
Min user = 
CALCULATE (
    MAX ( 'Table'[User] ),
    FILTER (
        ALL ( 'Table' ),
        [Difference] = MIN ( 'Table'[Difference] )
            && [deviceID] = SELECTEDVALUE ( 'Table'[deviceID] )
    )
)

vzhangti_1-1670810788714.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @Anonymous 

 

You can try the following methods.

Column:

Difference = DATEDIFF([firstSeen],[lastSeen],MINUTE)

vzhangti_0-1670810729695.png

Measure:

Max user = 
CALCULATE (
    MAX ( 'Table'[User] ),
    FILTER (
        ALL ( 'Table' ),
        [Difference] = MAX ( 'Table'[Difference] )
            && [deviceID] = SELECTEDVALUE ( 'Table'[deviceID] )
    )
)
Min user = 
CALCULATE (
    MAX ( 'Table'[User] ),
    FILTER (
        ALL ( 'Table' ),
        [Difference] = MIN ( 'Table'[Difference] )
            && [deviceID] = SELECTEDVALUE ( 'Table'[deviceID] )
    )
)

vzhangti_1-1670810788714.png

Is this the result you expect?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

FreemanZ
Super User
Super User

Hi  @Anonymous 

 

try to create two measures with this code:

MaxUser = 
VAR MaxDuration = 
MAXX(
    TableName, 
    TableName[LastSeen] - TableName[FirstSeen]
)
RETURN
CALCULATE(
    VALUES(TableName[User]),
    TableName[LastSeen] - TableName[FirstSeen] = MaxDuration
)

MinUser = 
VAR MinDuration = 
MINX(
    TableName, 
    TableName[LastSeen] - TableName[FirstSeen]
)
RETURN
CALCULATE(
    VALUES(TableName[User]),
    TableName[LastSeen] - TableName[FirstSeen] = MinDuration
)

 

I tried and it worked like this:

FreemanZ_0-1670658314937.png

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors