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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to count the occurrence of values in a column and display total correctly in same table

Hi all, 

 

I've got stuck trying to figure this out and was wandering if anyone could help guide me in the right direction.

 

I've got some project data like below. Each project has a corresponding point value which denotes how critical that project is. In the database I have hundreds of projects so I have slicers on the report that allows me to zoom in to certain types of project on my will.

Raw DataRaw Data

The end result I would like to have is as below. In case I choose to look at just the first 4 projects, the count should be able to change dynamically as well.

CountsCountsFirst 4 projects with countsFirst 4 projects with counts

Any suggestions on how to tackle this will be deeply appreciated.

 

Cheers,

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Anonymous

 

It looks like you want a measure that returns the number of projects with the same Points as the currently filtered Project, within the set of projects selected in the visual.

 

Assuming your table is called Projects and it contains one row per Project, this measure should do that:

 

Count =
CALCULATE (
    COUNTROWS ( Projects ),
    ALLSELECTED ( Projects ),
    VALUES ( Projects[Points] )
)

This measure sets the filter context on the Projects table to "all selected Projects", and adds a filter on the Points column corresponding to currently filtered Projects, then counts the Projects in that context.

 

Cheers,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

View solution in original post

8 REPLIES 8
OwenAuger
Super User
Super User

Hi @Anonymous

 

It looks like you want a measure that returns the number of projects with the same Points as the currently filtered Project, within the set of projects selected in the visual.

 

Assuming your table is called Projects and it contains one row per Project, this measure should do that:

 

Count =
CALCULATE (
    COUNTROWS ( Projects ),
    ALLSELECTED ( Projects ),
    VALUES ( Projects[Points] )
)

This measure sets the filter context on the Projects table to "all selected Projects", and adds a filter on the Points column corresponding to currently filtered Projects, then counts the Projects in that context.

 

Cheers,

Owen 🙂


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn

Hello Owen,

 

What if there are multiple rows for each project but I want the count to repeat in all the rows for that project?

 

Thanks!

Hello Owen,

 

What if there are multiple rows for each project but I want the count to repeat in all the rows for that project?

 

Thanks!

Just what I needed today too.  I knew it would be a simple looking formula.

When I perform this, all values end up counting the full set of rows (9). It's not filtered for only the values that match the current row; would expect values of 3.

 

=CALCULATE(COUNTROWS(Query1),ALLSELECTED(Query1),VALUES(Query1[Alias]))

 

DATA:

AssignmentIDAliasTitleAccountID
953202abcdeAccount Manager8825321
955780bcdefAccount Manager5305253
956871cdefgAccount Manager8688920
958597abcdeAccount Manager1566066
961119bcdefAccount Manager9647982
962453cdefgAccount Manager2401429
967272abcdeAccount Manager1511273
971636bcdefAccount Manager4349538
972643cdefgAccount Manager1426770
Anonymous
Not applicable

Hi @OwenAuger,

 

As I am developing my reports new problems come up and I wonder if you could shed some light again. Even if you could point me a direction that will be much appreciated.

 

Thanks for your porvided DAX I now have the correct count however I need to be able to differentiate those with the same count. Something like below. I would also need to be able to dynamically filter the column through slicers.

RankRankRank with filterRank with filter

 

Thanks,

Anonymous
Not applicable

Hi @OwenAuger,

 

Thanks for your reply. It works for me!!! 😄

 

Cheers,

Anonymous
Not applicable

Hi,
I think you could create a Dynamic table.

Step 1: create a new coloumm "count_temp" =1
Step 2 with SUMMARIZE function starting from your row data table crete the count value: CountTable =summarize(ProjectTable, ProjectTable [Points], "Count",SUM(ProjectTable [count_temp]))
Step 3: create a relationships betweem two tableau (double side) - Points to Points
Step 4: add you coloumn to your table

Hope It Will be useful

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.