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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MouserMike
Helper I
Helper I

Add OR to a Measure

I created a slicer along with a custom measure to allow me to filter a visual based on whether a particular field contained the value selected in the slicer. Below is the formual for the measure:

Impacted = 
IF (
    ISERROR (
        FIND (
            SELECTEDVALUE ( 'DepartmentStakeholders'[Department] ),
            SELECTEDVALUE ( Projects[ImpactedDepartments] )
        )
    ),
    0,
    1
)

How do I add an "OR" condition to also include projects with the same selected department in the Primary Department field?  I think it would be something like "OR SELECTEDVALUE = Projects[PrimaryDepartment]" but I'm not sure of the exact syntax.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@MouserMike -

Try something like this:

Your Measure = 
var a = FIND(SELECTEDVALUE('DepartmentStakeholders'[Department]),SELECTEDVALUE('Projects'[PrimaryDepartment]),1,0)  
var b = FIND(SELECTEDVALUE('DepartmentStakeholders'[Department]),SELECTEDVALUE('Projects'[ImpactedDepartments]),1,0)  
return MIN(MAX(a,b),1)

Hope this helps,

Nathan

 

View solution in original post

15 REPLIES 15
littlemojopuppy
Community Champion
Community Champion

Try something like this...

Impacted = 
IF (
    ISERROR (
        FIND (
            (SELECTEDVALUE ( 'DepartmentStakeholders'[Department] ) || 
            SELECTEDVALUE ( 'Projects'[PrimaryDepartment] )) &&
            SELECTEDVALUE ( Projects[ImpactedDepartments] )
        )
    ),
    0,
    1
)

image.png

Lose the double ampersand and replace with a comma

That removed the error, but now nothing is being returned when clicking a department in the slicer; results are always empty.

So I was never quite sure where you wanted the OR placed or if I had the field name correct.  The syntax should work and you should be very close...

The fieldnames are correct. 

The "OR" should be between  'Projects'[PrimaryDepartment] and 'Projects'[ImpactedDepartments]).  If either of those fields contain the 

SELECTEDVALUE ('DepartmentStakeholders'[Department], the result of the FIND should be True.

Did you try changing the measure appropriately?

I've updated the measure with each of your suggestions but am still getting the errors.

A couple things...

Without your PBIX file, I really can't tell you what the solution is.  I'm giving you my best guess.  I gave you how to incorporate AND and OR into measures...you need to figure it out.

More importantly, I've been participating in Microsoft forums covering VB/VBA, TSQL and Power BI for about ten years (Google my name to see!).  I've asked questions - and at times very stupid ones - and I've answered questions.  One thing I've learned is that it is extremely bad form to ask someone to "solve it for me".  People who are volunteering their time, effort and thought to help you want to see you trying as well.  Best of luck!

Anonymous
Not applicable

@MouserMike -

Try something like this:

Your Measure = 
var a = FIND(SELECTEDVALUE('DepartmentStakeholders'[Department]),SELECTEDVALUE('Projects'[PrimaryDepartment]),1,0)  
var b = FIND(SELECTEDVALUE('DepartmentStakeholders'[Department]),SELECTEDVALUE('Projects'[ImpactedDepartments]),1,0)  
return MIN(MAX(a,b),1)

Hope this helps,

Nathan

 

@Anonymous that's exactly what I was looking for. Thank you.

That is generating an error on the closed parenthesis after the last SELECTEDVALUE statement:

image.png

The double pipe - || - is the OR operator and the double ampersand - && - is the AND operator.  Check the parenthesis that everything is properly closed...

I checked and double-checked and as far as I can tell, everything is closed.  I don't understand how the || and && fit into the formula, but it seems to behave like there is a missing argument.

What is the error message?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.