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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Measure for counting unique users grouped by a parameter

Hi there!
Consider a table of facts. Each record contains user_id and some flag (true/false). I need to count unique users according to that flag and visualize it like a bar. For instance imagine that there're 10 users (10 records) with flag = "false" - (0, 10). After appending 2 records (12 records in total) where flag = "true" we get (2, 8), but not (2, 10). I came up with this measure which is as straight as possible, but gives no grouping at all.

 

unique_users = 
    VAR users_true = CALCULATETABLE(
        DISTINCT(users[user_id]),
        users[flag] = "true"
    )
    VAR users_false = CALCULATETABLE(
        DISTINCT(users[user_id])
    )

    RETURN SWITCH(
        TRUE(),
        "true" IN flags, COUNTROWS(users_true),
        COUNTROWS(users_false) - COUNTROWS(users_true)
    )

 

 

 img.png

 

 

 

Thank you beforehand and best regards!

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Try it.

unique_users = 
VAR users_true =
    SUMMARIZE(FILTER('users', users[flag] = "true" ),[user_id])
VAR users_false =
    SUMMARIZE('users',[user_id])
RETURN
 COUNTROWS ( users_false ) - COUNTROWS ( users_true )

The final output is shown below:

vyalanwumsft_0-1637808342890.png

Sorry I can't reproduce your data model, if this formula does not apply to your model, can you share simple files or scenarios?


Best Regards,
Community Support Team_ Yalan Wu
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

1 REPLY 1
v-yalanwu-msft
Community Support
Community Support

Hi, @Anonymous ;

Try it.

unique_users = 
VAR users_true =
    SUMMARIZE(FILTER('users', users[flag] = "true" ),[user_id])
VAR users_false =
    SUMMARIZE('users',[user_id])
RETURN
 COUNTROWS ( users_false ) - COUNTROWS ( users_true )

The final output is shown below:

vyalanwumsft_0-1637808342890.png

Sorry I can't reproduce your data model, if this formula does not apply to your model, can you share simple files or scenarios?


Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.