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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
D_PBI
Post Partisan
Post Partisan

How to sum values based on user slicer selection combination?

Hi,
I have created several Power BI Parameters that are set in the Power BI Service. These parameters are fed, via PQ, to the report. These parameters (these values) are used as a target value.
The team slicer visual consists of three teams (LS, PG, and AHSS). Each team has a parameter value.
I would like it so if the user selects all three teams (whether individually all, or through a 'select all') in the slicer then all three team's parameter values are summed.
If only, say, LS and PS teams are select then only the LS and PS parameters values are summed.
If only, say, LS teams is selected then only the LS parameter value is shown.

Below is my attempt at geting this to work.

__Deal target =

VAR _selectedvalues = VALUES( '__dim_Sub-Team'[Sub-Team] )

 

VAR _result =

IF(

    CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000000" && "200000001" && "200000002" ),

    VALUES( 'LS Deal target'[LS Deal target] ) + VALUES( 'PS Deal target'[PS Deal target] ) + VALUES( 'AHSS Deal target'[AHSS Deal target] ),

    IF(

        CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000000" && "200000001" ),

        VALUES( 'LS Deal target'[LS Deal target] ) + VALUES( 'PS Deal target'[PS Deal target] ),

        IF(

            CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000000" &&  "200000002" ),

            VALUES( 'LS Deal target'[LS Deal target] ) + VALUES( 'AHSS Deal target'[AHSS Deal target] ),

            IF(

                CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000001" && "200000002" ),

                VALUES( 'PS Deal target'[PS Deal target] ) + VALUES( 'AHSS Deal target'[AHSS Deal target] ),

                IF(

                    CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000000" ), //"LS"

                    VALUES( 'LS Deal target'[LS Deal target] ),

                    IF(

                        CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000001" ), //"PS"

                        VALUES( 'PS Deal target'[PS Deal target] ),

                        IF(

                            CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team],  "200000002" ), //"AHSS"

                            VALUES( 'AHSS Deal target'[AHSS Deal target] ),

                            100

                        )

                     )

               

                )

            )

        )

    )

)

 

RETURN

    _result + 0


What I get returned is the following error:

D_PBI_0-1716222994781.png


Please can someone help with this error?
Thanks.

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@D_PBI , I think the issue is because of the values , Try like

Deal Target =
VAR _selectedValues = VALUES('__dim_Sub-Team'[Sub-Team])
RETURN
SWITCH(
TRUE(),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000"),
SUM('LS Deal target'[LS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001"),
SUM('PS Deal target'[PS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUM('AHSS Deal target'[AHSS Deal target]),
100 // Default or other cases
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
v-xuxinyi-msft
Community Support
Community Support

Hi @D_PBI 

 

According to your error screenshot, the parameter types in your CONTAINS function have text type and true/false type, which cannot be compared, for example, "CONTAINS( _selectedvalues, '__dim_Sub-Team'[Sub-Team], "200000000" && " 200000001" && "200000002" )", where the first two arguments are text types and the latter is a true/false type. My current suggestion is that you need to change one of the parameter types in order for the comparison to work.

 

If your problem persists, please provide the sample data and the expected results based on the sample data so that I can better help you. How to provide sample data in the Power BI Forum - Microsoft Fabric Community Or show it as screenshots. Please remove any sensitive data in advance. 

 

Best Regards,
Yulia Xu

 

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

amitchandak
Super User
Super User

@D_PBI , I think the issue is because of the values , Try like

Deal Target =
VAR _selectedValues = VALUES('__dim_Sub-Team'[Sub-Team])
RETURN
SWITCH(
TRUE(),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('LS Deal target'[LS Deal target]), [LS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001") && CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUMX(VALUES('PS Deal target'[PS Deal target]), [PS Deal target]) +
SUMX(VALUES('AHSS Deal target'[AHSS Deal target]), [AHSS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000000"),
SUM('LS Deal target'[LS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000001"),
SUM('PS Deal target'[PS Deal target]),
CONTAINS(_selectedValues, '__dim_Sub-Team'[Sub-Team], "200000002"),
SUM('AHSS Deal target'[AHSS Deal target]),
100 // Default or other cases
)

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak - thank you. That worked as needed.
@v-xuxinyi-msft - thanks for your response. I have followed @amitchandak method to resolve the need.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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

Top Solution Authors