Forum Discussion

MouserMike's avatar
MouserMike
Helper I
7 years ago
Solved

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.

 

  • Anonymous's avatar
    Anonymous
    7 years ago

    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

     

15 Replies

  • littlemojopuppy's avatar
    littlemojopuppy
    Community Champion

    Try something like this...

    Impacted = 
    IF (
        ISERROR (
            FIND (
                (SELECTEDVALUE ( 'DepartmentStakeholders'[Department] ) || 
                SELECTEDVALUE ( 'Projects'[PrimaryDepartment] )) &&
                SELECTEDVALUE ( Projects[ImpactedDepartments] )
            )
        ),
        0,
        1
    )
    • MouserMike's avatar
      MouserMike
      Helper I

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

      • littlemojopuppy's avatar
        littlemojopuppy
        Community Champion

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