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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
murkysalt46
Frequent Visitor

COALESCE inside CALCULATE ignores FILTER

This DAX measure to count rows of table when year is not "2023", will return 0 when the year is "2023" (row context). I would prefer it to be blank as a value of 0 does not make sense for this year. 0 is still required for other years, however.  

 

 

CALCULATE(
    COALESCE(COUNTROWS( Table_A ), 0),
    FILTER( 
        Table_A, 
        Table_A[YEAR] <> "2023"
    )
)

 

 

 
Note that I cannot use external filters as this is part of a SWITCH, and "2023" may be required on other branches. 

5 REPLIES 5
v-cgao-msft
Community Support
Community Support

Hi @murkysalt46 ,

Try a branching structure with 2023 returning blank and the rest returning COALESCE(COUNTROWS( Table_A ), 0):

 

VAR __cur_year = SELECTEDVALUE('Table_A'[Year])
VAR __row_count = COUNTROWS('Table_A')
VAR __result = IF(__cur_year <> "2023",  COALESCE(__row_count,0))
RETURN
__result

 

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum -- China Power BI User Group

Thanks for taking the time to answer Gao. This works!....sometimes. As soon as a slicer is placed on TableA the 0's are filled in for "2023". I'll show with two snippets:

Without interaction of the slicer (blanks for col's with no data):

murkysalt46_0-1715212408490.png

With interaction (0's for columns with no data):

murkysalt46_1-1715212436297.png

Added a RAND() factor to obscure the data somewhat.

lbendlin
Super User
Super User

That's not what COALESCE is for. COUNTROWS never returns BLANK(), it always returns at least 0.

 

You code is equivalent to 

 

COUNTROWS(FILTER(Table_A,[Year]<>"2023"))

 

Make sure your year column is actually text.

Thanks for replying, but you are incorrect. These two queries produce different results.

In your example, COUNTROWS is not performed on the rows of the table where Year = "2023", therefore the result is blank. However, I need the result to be 0 where year is "2024", hence the COALESCE (or + 0). I suppose in my example above, it isn't clear that there isn't any data for "2024". But I need it to show 0 for all other values of year (just not "2023").

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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