Forum Discussion
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)
)
Thank you beforehand and best regards!
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:
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.
1 Reply
- v-yalanwu-msftCommunity 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:
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.