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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

CountIf with Dynamic Reference

Hi! I need to calculate a column in PBI which in Excel would look like this if I were entering the formula in cell C2:

 

=B2/Countif(A:A,A2)

 

Pretty simple in Excel. I've gotten this far with the formula in PBI:

 

ShipmentCost = CALCULATE(
COUNT(ShipmentLevel[Shipment Gid]),
FILTER(ShipmentLevel,
 
Where 'ShipmentLevel' is the table and [Shipment Gid] is the id I want to reference dynamically.
 
But I can't figure out how to input a dynamic reference based on the row being calculated. AND I can't figure out how to reference what would be cell "b2" in my excel example above.
 
Any help here?
1 ACCEPTED SOLUTION

@Anonymous add new measure "c" with following expression and test

 

c = DIVIDE( SUM( Table2[b] ), CALCULATE( COUNT( Table2[a] ), ALLEXCEPT( Table2, Table2[a] ) ) )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
parry2k
Super User
Super User

@Anonymous I never used countif, could you please share exactly what you are trying to do? And also how your tables are related? In your countif example, isn't 2nd parameter should be a criteria instead of single cell.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hey @parry2k

 

I'm trying to divide an number by the count of rows with the same reference ID. For example, in the below table the reference ID "ID123" shows up 3 times throughout.

 

         a              b            c

1     ID123       101

2     ID002       243

3     ID123       101

4     ID123       101

5     ID002       243

6     ID002       243

7     ID002       243

 

I would like in cell c1 to show 101 / 3. However in cell c2, I would want to see 243 / 4 because the countif will only count rows with an ID that matches the ID in the current row. Hence the cell instead of a hard coded criteria. At least that's how it works in excel. How can I accomplish this in PBI?

 

Thanks!!

  

@Anonymous add new measure "c" with following expression and test

 

c = DIVIDE( SUM( Table2[b] ), CALCULATE( COUNT( Table2[a] ), ALLEXCEPT( Table2, Table2[a] ) ) )


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors