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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
DamianKelly
Frequent Visitor

How to do 'CountIfs' in Power Query or in DAX!

Can anybody please help me understand how to make this simple Excel Countif work in Power Query or DAX, please?! 😞

DamianKelly_0-1716470359967.png

 

1 ACCEPTED SOLUTION
m_dekorte
Super User
Super User

Hi @DamianKelly 

 

In Power Query, Group By is useful for these types of requirements:

let
    Source = YourData,
    GroupByRows = Table.Group(Source, {"Product"}, {
        {"AllRows", each _, type table [Product=nullable text, Period=nullable text, Supply=nullable number]}, 
        {"SupplyCount", each List.Count(List.Select([Supply], (x)=> Number.From(x??0) >0 )), type nullable number}
    }),
    ExpandAllRows = Table.ExpandTableColumn(GroupByRows, "AllRows", {"Period", "Supply"}, {"Period", "Supply"})
in
    ExpandAllRows

 

In DAX you could do something like this:

CountIfs = 
VAR curValue = SELECTEDVALUE( 'YourTable'[Product] )
VAR t = 
    FILTER( 
        ALL( 'YourTable'),
        [Product] = curValue &&
        [Supply] >0
    )
RETURN

COUNTROWS( t )

 

In a table visual, that will get you these results:

m_dekorte_0-1716483367195.png

 

I hope this is helpful

View solution in original post

1 REPLY 1
m_dekorte
Super User
Super User

Hi @DamianKelly 

 

In Power Query, Group By is useful for these types of requirements:

let
    Source = YourData,
    GroupByRows = Table.Group(Source, {"Product"}, {
        {"AllRows", each _, type table [Product=nullable text, Period=nullable text, Supply=nullable number]}, 
        {"SupplyCount", each List.Count(List.Select([Supply], (x)=> Number.From(x??0) >0 )), type nullable number}
    }),
    ExpandAllRows = Table.ExpandTableColumn(GroupByRows, "AllRows", {"Period", "Supply"}, {"Period", "Supply"})
in
    ExpandAllRows

 

In DAX you could do something like this:

CountIfs = 
VAR curValue = SELECTEDVALUE( 'YourTable'[Product] )
VAR t = 
    FILTER( 
        ALL( 'YourTable'),
        [Product] = curValue &&
        [Supply] >0
    )
RETURN

COUNTROWS( t )

 

In a table visual, that will get you these results:

m_dekorte_0-1716483367195.png

 

I hope this is helpful

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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