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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Forthe3kids
New Member

Add measure to count not null values but return 0 for null values

Hi, I have a Power BI measure issue that I can use some assistance in solving.

I want to count number of records within a table that are not null, however I still want records with null values to appear with count of 0. I have tried various Calculate DAX expresssions but so far no luck.

Product table example data

Forthe3kids_0-1715793213224.png

 

Power Bi report

Forthe3kids_1-1715793228132.png

When I add the measure: Measure  = Count(Products[Sales])   the Sprocket West record no longer shows

Forthe3kids_2-1715793254679.png

If I change the measure to: Measure = COUNTROWS(DISTINCT(Products[Sales]))   The Sprocket West record shows but with the wrong count desired, it is counting rows.

Forthe3kids_3-1715793283541.png

Desired report output would not include the Sales column but should have a measure value of 0 for Sprocket West, not a value of 1 as shown below

Forthe3kids_4-1715793321712.png

 

Does anyone have any suggestions I can try?

Thanks

4 REPLIES 4
v-heq-msft
Community Support
Community Support

Hi  @Forthe3kids ,
You can try this measure

Result = 
IF(
    ISFILTERED('Table'[Sales]),
    IF(
        SELECTEDVALUE('Table'[Sales]) <> BLANK(),
        COUNT('Table'[Sales]),
        0
    ),
    CALCULATE(
        COUNT('Table'[Sales]),
        FILTER(
            'Table',
            'Table'[Sales] <> BLANK()
        )
    )
)

Final output
vheqmsft_0-1715928408798.png

Best regards,
Albert He

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Albert, 

thank you for the reply, unfortunately this did not solve my problem, records with null value for sales do not appear.  Reminder, in the report output i do not want to display the sales nor material columns. I only want product, location and count of sales. This is also a multi table query from an analytical model, thus i cannot transform the data nor use power query and add a column.

Thanks

Dave

Forthe3kids
New Member

Thank you for thie reply, for my simple example, yes the  "+0" solves the problem.

My appologies, I should have added that the true business case is a report based on an analytic model using multiple tables (Hundred thousand + records). Using the +0 results in a cross-join between the multi-table joins and will produce horrendous performance issues.  

Thank you

ryan_mayu
Super User
Super User

maybe you can try this

Measure  = Count(Products[Sales])  + 0





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.