Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
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.
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):
With interaction (0's for columns with no data):
Added a RAND() factor to obscure the data somewhat.
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...
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
147 | |
85 | |
66 | |
52 | |
46 |
User | Count |
---|---|
215 | |
90 | |
83 | |
66 | |
58 |