cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
MulberyPie
Advocate I
Advocate I

Counting Pairs and displaying value next to them

I want to count how many times a specific pair of values occur and display the count next to them. How would I count a set of values and duplicate the count x number of times to line up with original value?

 

MulberyPie_0-1653081685246.png

For this table the pairs would be in plant and type. So 'tree' & 'seed' show up 2 times, 'bush' & 'leaf' 3 times etc. How would I count that and then put a 2 next to each instance of tree and seed, and a 3 next to bush and leaf? Could I possibly make a new table with duplicates removed and then just count the pairs and put the total in the corresponding column? I want to be able to update the data and have it automatically recount the pairs so I don't know if making new tables is the best idea.

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Plant]=EARLIER(Table1[Plant])&&Table1[Type]=EARLIER(Table1[Type])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Plant]=EARLIER(Table1[Plant])&&Table1[Type]=EARLIER(Table1[Type])))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ChrisMendoza
Resident Rockstar
Resident Rockstar

@MulberyPie -
You can do as a column:

Column = 
VAR __pair = TableName[Plant] & TableName[Type]
VAR Result =
CALCULATE(
    COUNTROWS(TableName),
    TableName[Plant] & TableName[Type] = __pair
)
RETURN Result

image.png

or as a measure:

Measure = 
VAR __pair = SELECTEDVALUE(TableName[Plant]) & SELECTEDVALUE(TableName[Type])
VAR Result =
CALCULATE(
    COUNTROWS(TableName),
    TableName[Plant] & TableName[Type] = __pair
)
RETURN Result

image.png

 






Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



I have a lot more columns than what is shown. When I use the column method it shows 1's next to every row, but when that column is put into a table with just the pair coulmns it shows a total, but that total has some wrong numbers. Some of the counts for the pairs are right, but some are too high.  I think that having extra columns that can vary with the pair may mess up the new column method.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

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

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors