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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Tevon713
Helper V
Helper V

Switch function based on selection filter to another table value

Hi all, 

 

Got 2 tables, I want to switch or return value in another table then use that for a measure calculation. 

See below measure created, it not working.

 

Selected_Measure =
VAR Selection = SELECTEDVALUE (Table[Region])
RETURN
SWITCH ( TRUE(),
Selection = "NE", Table2[Region]="NORTHEAST REGION",
Selection = "SW", Table2[Region]="SOUTHWEST REGION",
Selection = "WEST", Table2[Region]="WEST REGION",
Table2[Region]="ALL"
)

1 ACCEPTED SOLUTION

Hi @Tevon713 

 

This error occurs because Table2[Region]=[Selected_Measure] portion is used as a filter expression in CALCULATE function. To avoid this error, you can try the following measure. Add a variable to get the measure value in advance, then use the value in CALCULATE. 

Matches Count =
VAR __value = [Selected_Measure]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table2[Acct Num] ),
        FILTER (
            Table2,
            LOOKUPVALUE ( Table1[Acct Num], Table1[Acct Num], Table2[Acct Num] )
        ),
        Table2[Region] = __value
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @Tevon713 

 

A measure is to display the results in a visual rather than in a data table. You can add below measure into a visual (e.g. a table visual) along with other necessary columns from Table2 to see the result. 

Selected_Measure =
VAR Selection = SELECTEDVALUE ( Table[Region] )
RETURN
    SWITCH (
        TRUE (),
        Selection = "NE", "NORTHEAST REGION",
        Selection = "SW", "SOUTHWEST REGION",
        Selection = "WEST", "WEST REGION",
        "ALL"
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

Thanks @v-jingzhang.

 

Tried previously. I'm getting this message when trying to use it return value. Intent is to look for if that account number exist in another table for that selected region.

 

A function 'PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 

Matches Count = CALCULATE(DISTINCTCOUNT(Table2[Acct Num]) , FILTER(Table2,LOOKUPVALUE(Table1[Acct Num],Table1[Acct Num], Table2[Acct Num])), Table2[Region]=[Selected_Measure])

 

Tevon713_0-1671109649717.png

 

 

Hi,

To overcome this error, you may also use FILTER function instead of direct filter expression. Filteration in measures does not work directly in expression, but works with FILTER function.

 

Example: Replace with below.

 

FILTER(Table2, [Region]=[Selected_Measure])

Hi @Tevon713 

 

This error occurs because Table2[Region]=[Selected_Measure] portion is used as a filter expression in CALCULATE function. To avoid this error, you can try the following measure. Add a variable to get the measure value in advance, then use the value in CALCULATE. 

Matches Count =
VAR __value = [Selected_Measure]
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Table2[Acct Num] ),
        FILTER (
            Table2,
            LOOKUPVALUE ( Table1[Acct Num], Table1[Acct Num], Table2[Acct Num] )
        ),
        Table2[Region] = __value
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it. Highly appreciate your Kudos!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.