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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Countif with multiple criteria

Hello, I'm working on a dataset which has Vendor IDs and Vendor Amount and would like to be able to count how many times the same vendor has made a sale for the same amount. Something like this:

 

Vendor NameSale AmountRepeats
Netflix53
Google102
Apple153
Walmart52
Apple153
Google81
Netflix53
Walmart101
Apple153
Apple251
Walmart52
Netflix53
Google102

 

The formula in Excel would be =COUNTIFS(VendorSales[[#All],[Vendor Name]],[@[Vendor Name]],VendorSales[[#All],[Sale amount]],[@[Sale amount]])

 

I'm thinking most of my problem lies on the @ [field] part of it cause I could use a calculate with a filter.

 

Thanks!

2 REPLIES 2
TomMartens
Super User
Super User

Hey,

 

this calculated column provides what you are looking for:

col Count = 
var thisVendor = 'Table1'[Vendor Name]
var thisSaleAmount = 'Table1'[Sale Amount]
return
CALCULATE(
    COUNTROWS('Table1')
    ,ALL('Table1')
    ,'Table1'[Vendor Name] = thisVendor
    ,'Table1'[Sale Amount] = thisSaleAmount
)

Just a little recap:
As there is no Filter Context present if the DAX statement of a calculated column gets evaluated it's possible to store the values of the columns Vendor Name and Sales Amount from the current row into variables. The first thing that happens if the CALCULATE formulat gets evaluated is the so called context transition, a Row Context is transformed into a Filter Context. COUNTROWS(...) just counts the number of rows. First all existing filter get removed using ALL and the filter for Vendor Name and Sales Amount get reapplied.

 

image.png


Please be aware of the "Default Summarization" of the calculated column, you might need it to change accordingly. From the Data view --> Menu Modeling --> Default Summarization (from the Properties ribbon)

Hopefully this is what you are looking for.

Regards,

Tom

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

Hi @Anonymous 
I think there are many ways to achieve this.

Here is my code:

Column = CALCULATE(COUNTROWS('T1'),
FILTER(T1,T1[Vendor Name] =  EARLIER(T1[Vendor Name])),
FILTER(T1,T1[Sale Amount] =  EARLIER(T1[Sale Amount])))

2019-04-24 14_49_10-papercut - Remote Desktop Connection.png

 

Thanks!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors
Users online (12,449)