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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
WestWinter
Helper II
Helper II

Changing code to reference a slicer?

Hi All,
 
So I have the below code which gives the value in TableA, where the field is "Asia" and the id matches in Table A with Table B.

 

 

ExposureA =
VAR Output = CALCULATE(SUM(TableA[value]),
FILTER(TableA, TableA[field] = "Asia" && TableA[id] = selectedvalue(TableB[id]))
)

RETURN Output​

 

 

How do I rejigger it so that instead of just "Asia", it is able to accept other fields in TableA[field], via a dropdown box using a Slicer, and then ExposureA to be showing values from that particular field? So this should return in a table, whatever is filtered via the slicer (e.g. North America, if I choose), instead of just a static "Asia"?
 
So for example, in field there are multiple continents:
field
Asia
North America
Europe
Africa
 Thanks
 
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @WestWinter ,

According to your description, field and value are all in tableA, you want the measure filtered by the field slicer, you don’t need to write TableA[field]=””, just put field in slicer, it automatically works.

ExposureA =
CALCULATE (
    SUM ( 'TableA'[Value] ),
    FILTER ( 'TableA', 'TableA'[ID] = MAX ( 'TableB'[ID] ) )
)

vkalyjmsft_0-1638266743778.png

Best Regards,
Community Support Team _ kalyj

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

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @WestWinter ,

According to your description, field and value are all in tableA, you want the measure filtered by the field slicer, you don’t need to write TableA[field]=””, just put field in slicer, it automatically works.

ExposureA =
CALCULATE (
    SUM ( 'TableA'[Value] ),
    FILTER ( 'TableA', 'TableA'[ID] = MAX ( 'TableB'[ID] ) )
)

vkalyjmsft_0-1638266743778.png

Best Regards,
Community Support Team _ kalyj

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

AlexisOlson
Super User
Super User

You should be able to use SELECTEDVALUE just like you do with [id].

 

ExposureA =
VAR Output =
    CALCULATE (
        SUM ( TableA[value] ),
        FILTER (
            TableA,
            TableA[field] = SELECTEDVALUE ( SlicerTable[field] )
                && TableA[id] = SELECTEDVALUE ( TableB[id] )
        )
    )
RETURN
    Output​

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.