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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply

IF(ISBLANK() ignores data model relationships?

I am using the following measure:

Number of training days = CALCULATE(IF(ISBLANK(DISTINCTCOUNT('Fact Core Training Log'[Training Log ID])), 0, (DISTINCTCOUNT('Fact Core Training Log'[Training Log ID]))))
 
However, it seems to ignore relationships and return '0' for every employee. The employees all have a department, and i have a filter set on the dashboard so it only shows me employees within the set department.
 
I therefore expect to see around 15 employees for this department. There are 2 employees whose training log count is 0 and therefore would not show in the data table if i just do a distinct count of 'Fact Core Training Log'[Training Log ID]. I want these to show as 0 so have used the measure above. 
 
It works in the sense it shows me these 2 employees and gives them a count of 0. However, it also lists every other employee in the database even though the filter is on to a department they are not in or related to in the model.
 
Is there a tweak I can make to the measure to correct this?
 
My filter is DepartmentID = '1' (coming from DimDepartment table).
Any help is appreciated.
1 ACCEPTED SOLUTION

Hi, @lloydthomas2399 

 

Department table:

vzhangti_0-1697536514938.png

 

Number of training days = 
VAR _N1 =
    CALCULATE ( DISTINCTCOUNT ( 'Fact Core Training Log'[Training Log ID] ),
        FILTER ( ALL( 'Fact Core Training Log' ),
            [Department] = MAX ( 'Fact Core Training Log'[Department] )
                && [Employee] = MAX (Department[Employee]) ) ) 
RETURN
 IF ( _N1=BLANK(), 0, _N1 )

 

vzhangti_2-1697536615496.png

vzhangti_1-1697536606339.png

Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

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

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@lloydthomas2399 , You have to control range or some other values

 

example

 

0 between range
Measure = var _1= SUM(Opportunity[Opportunity count]) +0
var _min = minx(ALLSELECTED('Calendar'), 'Calendar'[Date])
var _max = maxx(ALLSELECTED('Calendar'), 'Calendar'[Date])
return
if(max('Calendar'[Date]) <_min || max('Calendar'[Date]) >_max , BLANK(), _1)

Thanks for the reply, would you be able to structure your measure to suit my example please? I'm not interested in date it's just my training log and department table.

Hi, @lloydthomas2399 

 

Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures. I look forward to your response.

 

Best Regards,

Community Support Team _Charlotte

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

Hi @v-zhangti , thank you for your reply. Let me detail below for you.

 

So, as mentioned I have a FactTrainingLog table and several dimension tables. One dimension table DimEmployee another DimDepartment. I want to show, in a data table, the number of times and employee has completed a training course. Only one department are required to do this training course, so the dashboard will have a filter of DimDepartment = 'Flex'.

 

I therefore want to count on the TrainingLogID in the FactTrainingLog table. Doing so, gives me each employee in the flex department and the number of times they've done the training, but only if they've done it at least once, e.g:

EmployeeDepartmentCount of TrainingLogID
Person 1Flex12
Person 2Flex7
Person 3Flex6
Person 4Flex2
Person 5Flex1
Person 6Flex 

1

 

So doing a distinct count works fine, obviously. However, I need to show a count of 0 for those employees who have never done the training, so the table would look like so:

 

EmployeeDepartmentCount of TrainingLogID
Person 1Flex12
Person 2Flex7
Person 3Flex6
Person 4Flex2
Person 5Flex1
Person 6Flex 

1

Person 7Flex

0

Person 8Flex

0

 

So to acomplish the above, I tried to use the following measure:
Number of training days = CALCULATE(IF(ISBLANK(DISTINCTCOUNT('Fact Core Training Log'[Training Log ID])), 0, (DISTINCTCOUNT('Fact Core Training Log'[Training Log ID]))))

Now, in a way this works but incorrectly. Whilst it then gives me Person 7 & 8 in the table with a count of 0, it also brings in every other employee in the database and gives them a count of 0 and also attaches them to Flex department even though that is not their department? If I remove my department filter (DimDepartment = 'Flex') then every employee is attached to every department, e.g. Person 1 would then show in the table as 

EmployeeDepartmentCount of TrainingLogID
Person 1Flex12
Person 1Red0
Person 1Blue0
Person 1Green 0

 

So, the measure just seems to ignore the data model relationship/filter?

 

Your help would be appreciated.

Hi, @lloydthomas2399 

 

You can try the following methods.

Number of training days = 
VAR _N1 =
    CALCULATE ( DISTINCTCOUNT ( 'Fact Core Training Log'[Training Log ID] ),
        FILTER ( ALL ( 'Fact Core Training Log' ),
            [Department] = SELECTEDVALUE ( 'Fact Core Training Log'[Department] )
                && [Employee] = SELECTEDVALUE ( DimEmployee[Employee] ) ) )
RETURN
    IF ( ISBLANK(_N1), 0, _N1 )

vzhangti_0-1697532565328.png

Please try again to bring in the remaining Departments and see the results.

 

Best Regards,

Community Support Team _Charlotte

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

 

Hi @v-zhangti  , unfortunately this doesn't work. It still brings in employees not related to the department. I've edited your pbix and added Person 9, added them to 'Green' department and they still are showing when the flex department is selected...

lloydthomas2399_0-1697534339967.png

 

lloydthomas2399_1-1697534372255.png

Similarly, if you select 'Green' from the dept slicer, Persons 1-8 show in the table when they shouldn't as theyre Flex dept.

lloydthomas2399_2-1697534589381.png

 

Hi, @lloydthomas2399 

 

Department table:

vzhangti_0-1697536514938.png

 

Number of training days = 
VAR _N1 =
    CALCULATE ( DISTINCTCOUNT ( 'Fact Core Training Log'[Training Log ID] ),
        FILTER ( ALL( 'Fact Core Training Log' ),
            [Department] = MAX ( 'Fact Core Training Log'[Department] )
                && [Employee] = MAX (Department[Employee]) ) ) 
RETURN
 IF ( _N1=BLANK(), 0, _N1 )

 

vzhangti_2-1697536615496.png

vzhangti_1-1697536606339.png

Please see the attached document.

 

Best Regards,

Community Support Team _Charlotte

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

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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