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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply

COUNTIFS in Power BI with individual rows

Hi there,

 

I'm currently trying to move my excel sheets over to Power BI, however I'm having trouble with some COUNTIFS.

 

My current excel formula is like so:

 

Power BI Question

 

I'm currently using this formula in individual columns in Power BI:

 

NUMBER = CALCULATE(COUNTROWS('Table'),FILTER('Table','Table'[YEAR] = "18" && 'Table'[CODE] = "CODE1"))
 
But I would like the Number to be calculated all in one column, with the "18" and "CODE1" to be chosen from the individual rows, as I have it in Excel.
 
Any help is much appreciated
1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @michaelmichael 

 

Try this.

NUMBER = 
    CALCULATE( 
        COUNTROWS( 'Table' ), 
        ALLEXCEPT( 
            'Table', 
            'Table'[CODE], 'Table'[YEAR]
        ) 
    )
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

View solution in original post

4 REPLIES 4
Mariusz
Community Champion
Community Champion

Hi @michaelmichael 

 

Try this.

NUMBER = 
    CALCULATE( 
        COUNTROWS( 'Table' ), 
        ALLEXCEPT( 
            'Table', 
            'Table'[CODE], 'Table'[YEAR]
        ) 
    )
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

Thanks @Mariusz, that worked!

 

What if I wanted to use ALLEXCEPT and FILTER ?

 

i.e. I want to have the individual row filters, and also wanted to have a fixed filter such as "CODE1", etc

 

Something like so...?

 

NUMBER = CALCULATE(COUNTROWS( 'Table' ), ALLEXCEPT( 'Table', 'Table'[YEAR] ), FILTER('Table','Table'[CODE] = "CODE1"))
 

Regards,

Mike

I think I figured it out by using the FILTER outside of the ALLEXCEPT
 
NUMBER=CALCULATE(COUNTROWS('Table'),FILTER(ALLEXCEPT('Table','Table'[YEAR]),'Table'[CODE]="CODE1"))
 
Thanks

Hi @michaelmichael 

 

Happy you worked it out.

 

Thanks

Mariusz 

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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