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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
jabueg
Frequent Visitor

Adding Condition to Switch Measure to Output "0"

Hi! Need to add a condition to my Switch measure "Total Dynamic Calls" 
I want it to output "0" for SUM of [Total Calls] from the 'Combined Call Logs 5/17' table if the value "Field" from the UpdatedProd521 [Enrollment Type] table is selected in a slicer.



Otherwise, it should output SUM Total Calls if the value "Call Center" is selected. Thanks in advance!

Here is the current Switch measure:
 

Total Calls Dynamic =

SWITCH(
    TRUE(),

    // Case 1: Single Advisor AND Single Date selected
    HASONEVALUE(UpdatedProd521[Advisor]) &&
    HASONEVALUE(UpdatedProd521[Date]),

    CALCULATE(
        SUM('Combined Call Logs 5/17'[CALLS]),
        USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]),
        FILTER(
            'Combined Call Logs 5/17',
            'Combined Call Logs 5/17'[DATE] = VALUES(UpdatedProd521[Date])
        )
    ),

    // Case 2: Only Advisor is selected
    HASONEVALUE(UpdatedProd521[Advisor]),

    CALCULATE(
        SUM('Combined Call Logs 5/17'[CALLS]),
        USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR])
    ),

    // Case 3: Only Date is selected
    HASONEVALUE(UpdatedProd521[Date]),

    CALCULATE(
        SUM('Combined Call Logs 5/17'[CALLS]),
        USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date])
    ),

 

    // Default: sum all calls if no or multiple selections
    SUM('Combined Call Logs 5/17'[CALLS])
)
1 ACCEPTED SOLUTION
SamsonTruong
Solution Supplier
Solution Supplier

Hi @jabueg,

This can be achieved by using the SELECTEDVALUE() function to determine which value is currently selected in the slicer. The measure below checks for a specific selection and adjusts the output accordingly:

Total Calls Dynamic = 
VAR IsFieldSelected =
    SELECTEDVALUE(UpdatedProd521[Enrollment Type]) = "Field"

RETURN
IF (
    IsFieldSelected,
    0,
    SWITCH(
        TRUE(),

        // Case 1: Single Advisor AND Single Date selected
        HASONEVALUE(UpdatedProd521[Advisor]) &&
        HASONEVALUE(UpdatedProd521[Date]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]),
            FILTER(
                'Combined Call Logs 5/17',
                'Combined Call Logs 5/17'[DATE] = VALUES(UpdatedProd521[Date])
            )
        ),

        // Case 2: Only Advisor is selected
        HASONEVALUE(UpdatedProd521[Advisor]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR])
        ),

        // Case 3: Only Date is selected
        HASONEVALUE(UpdatedProd521[Date]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date])
        ),

        // Default: sum all calls if no or multiple selections
        SUM('Combined Call Logs 5/17'[CALLS])
    )
)

 

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

View solution in original post

4 REPLIES 4
jabueg
Frequent Visitor

@SamsonTruong This worked perfectly. Thanks, Samson!

@jabueg glad to hear it worked!

SamsonTruong
Solution Supplier
Solution Supplier

Hi @jabueg,

This can be achieved by using the SELECTEDVALUE() function to determine which value is currently selected in the slicer. The measure below checks for a specific selection and adjusts the output accordingly:

Total Calls Dynamic = 
VAR IsFieldSelected =
    SELECTEDVALUE(UpdatedProd521[Enrollment Type]) = "Field"

RETURN
IF (
    IsFieldSelected,
    0,
    SWITCH(
        TRUE(),

        // Case 1: Single Advisor AND Single Date selected
        HASONEVALUE(UpdatedProd521[Advisor]) &&
        HASONEVALUE(UpdatedProd521[Date]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR]),
            FILTER(
                'Combined Call Logs 5/17',
                'Combined Call Logs 5/17'[DATE] = VALUES(UpdatedProd521[Date])
            )
        ),

        // Case 2: Only Advisor is selected
        HASONEVALUE(UpdatedProd521[Advisor]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP(UpdatedProd521[Advisor], 'Combined Call Logs 5/17'[ADVISOR])
        ),

        // Case 3: Only Date is selected
        HASONEVALUE(UpdatedProd521[Date]),
        CALCULATE(
            SUM('Combined Call Logs 5/17'[CALLS]),
            USERELATIONSHIP('Combined Call Logs 5/17'[DATE], UpdatedProd521[Date])
        ),

        // Default: sum all calls if no or multiple selections
        SUM('Combined Call Logs 5/17'[CALLS])
    )
)

 

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

Kudo 👌

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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