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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
alisaleh
Helper I
Helper I

replacing blank with 0 cause the filter not to work correctly

Hi,

I have scenario where I have 1:*  active relationship from project table to JobCard table. I have created a measure to count the number of Job Card based on selected Project where I have project slicer. The DAX for the measure is as follows:

 

Total Project Job Card =
var temp= CALCULATE(COUNT('jobCard'[id]),'jobCard'[project] == SELECTEDVALUE('Project'[name]))
return If(ISBLANK(temp),0,temp)

 

The problem Im having is when I change the project in the slicer its always showing job cards from anohter

project with 0 values for total. If I remove the condition to replace blank with 0 then it filters correctly

and when I select project with no job cards nothing shows!! why this is happening desipite the measure is filter

by selected project? How do I fix it so it shows 0 for blanks when there is job card associated with the project and show nothing when there is no association.

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@alisaleh 

Please try

Total Project Job Card =
VAR temp =
    CALCULATE (
        COUNT ( 'jobCard'[id] ),
        'jobCard'[project] == SELECTEDVALUE ( 'Project'[name] )
    )
RETURN
    IF ( NOT ISEMPTY ( 'jobCard' ), COALESCE ( temp, 0 ) )

View solution in original post

5 REPLIES 5
alisaleh
Helper I
Helper I

Thanks. it put me on the right path.

@alisaleh Do you recall how you got the formula to work?  I was running into the issue where the is not empty excludes my blanks, so the coalesce never gets the chance to return the 0.  

Hi @jvirgi 

can you provide some exsmples?

@tamerj1 I found the issue.  Ill use the same names as the OP.  I adjusted your formula to put the Project table into the Not ISempty function rather than the jobcard table.   

 

My issue with the formula was we want to replace the blanks when that jobcard table is blank, so the function you had skips the coalesce in this case; but works well when putting the project table there. I think this was the same issue @alisaleh 

tamerj1
Super User
Super User

@alisaleh 

Please try

Total Project Job Card =
VAR temp =
    CALCULATE (
        COUNT ( 'jobCard'[id] ),
        'jobCard'[project] == SELECTEDVALUE ( 'Project'[name] )
    )
RETURN
    IF ( NOT ISEMPTY ( 'jobCard' ), COALESCE ( temp, 0 ) )

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors