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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Count the no. of occurrences of id's in a table using calculated column

Hi All,

 

I Have a table with:  id, user_id , created_date

 

I tried to find the no. of times user appers in the table using this:

 

CountUsers = CALCULATE(
    COUNTA('public accounts_usersession'[user_id]);
    FILTER('public accounts_usersession';
        'public accounts_usersession'[user_id] = EARLIER('public accounts_usersession'[user_id])))

 But when I am filtering the data 'yearly' it still shows me the whole value and not the changed value. 

Screenshot_53.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

When I selected the year in the filter, it's giving me the same count for the users (in the example user_id = 601).

 

Screenshot_54.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

I desired output here should be 5 for user_id = 601 in the year 2018.

1 ACCEPTED SOLUTION

Ah you'll need to make this a measure rather than a column. Columns are always static info.

 

Wouldn't be very different from what you already have:

 

 

CountUsers = COUNTA('public accounts_usersession'[user_id])

 

No need to have the filter expression.

 

Then you would have something along the lines of:

 

 

User_Distributuion = 
           IF([CountUsers] = 1, "1x",
           IF([CountUsers] = 2 || [CountUsers] = 2, "2 -3x",
.....

 

Which returns something like this:

 

sssshrthrthrsth.PNG

 

Your bucket measure can only be used in the "Values" section of a visual. Gets a bit more complicated if you want to use these buckets as an axis on a graph.

View solution in original post

3 REPLIES 3
Veles
Advocate V
Advocate V

I'm guessing you've made this as a calculated column?

 

You should be able to do this without making a DAX expression at all.

 

Just put your user_id into the values field of a visual and click on the little arrow next to it and select Count (Distinct).

 

Give that a go and if it's not what you need then there'll be a DAX expression that will work.

 

svfsfsf.PNG

 

EDIT: Looking at your data you might just need Count rather than Count (Distinct)

Anonymous
Not applicable

@Veles Thank you for your reply. 

 

Yes I made this as a calculated column because I calculated the user_distribution based on this column. That you can see in the image. 

User distribution:

 

User_Distribution = IF('public accounts_usersession'[CountUsers] = 1 ; "1x";
                    IF('public accounts_usersession'[CountUsers] = 2 ; "2 -3x";
                    IF('public accounts_usersession'[CountUsers] = 3 ; "2 -3x";
                    IF('public accounts_usersession'[CountUsers] = 4 ; "4 -5x";
                    IF('public accounts_usersession'[CountUsers] = 5 ; "4 -5x";
                    IF('public accounts_usersession'[CountUsers] = 6 ; "6 -10x";
                    IF('public accounts_usersession'[CountUsers] = 7 ; "6 -10x";
                    IF('public accounts_usersession'[CountUsers] = 8 ; "6 -10x";
                    IF('public accounts_usersession'[CountUsers] = 9 ; "6 -10x";
                    IF('public accounts_usersession'[CountUsers] = 10 ; "6 -10x"; "> 10"))))))))))

Final destination is to play around with the user_distribution which depends on the Countusers.

 

Ah you'll need to make this a measure rather than a column. Columns are always static info.

 

Wouldn't be very different from what you already have:

 

 

CountUsers = COUNTA('public accounts_usersession'[user_id])

 

No need to have the filter expression.

 

Then you would have something along the lines of:

 

 

User_Distributuion = 
           IF([CountUsers] = 1, "1x",
           IF([CountUsers] = 2 || [CountUsers] = 2, "2 -3x",
.....

 

Which returns something like this:

 

sssshrthrthrsth.PNG

 

Your bucket measure can only be used in the "Values" section of a visual. Gets a bit more complicated if you want to use these buckets as an axis on a graph.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.