Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

In PowerBI DAX how do you count where column is in a list

How do I create a measure to count the number of customers where the customer type is either FR or DE or GG.

In SQL, this would be something like

SELECT COUNT(customerId) 
FROM dCustomers 
WHERE customerType IN ('FR', 'DE', 'GG')

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I would suggest using the IN operator, to write it in a more concise manner:

Count (Calculate) = 
CALCULATE (
    COUNTROWS ( dCustomers ) ,
    dCustomers[customerType] IN {"FR", "DE", "GG"}
)

You can also use COUNTROWS directly on the filtered table, this looks to be marginally faster from a bit of testing on a random dataset, but please do benchmarking on a case by case basis:

Count (Filter) = 
COUNTROWS ( 
    FILTER (
        dCustomers ,
        dCustomers[customerType] IN {"FR", "DE", "GG"}
    )
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading