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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Return filtered column if any in a measure as a variable

Hello everyone

 

I am trying to create a one-size-fits-all measure for multiple tables, but I got stuck somewhere.

 

Below is a dummy case:

 

Raw Data

 

YearStoreProductLocationRevenue
1/1/2019AIce CreamNew York $           500
1/1/2019ABeerNew York $           500
1/1/2019BIce CreamLittle Rock $           100
1/1/2019BBeerLittle Rock $           500
1/1/2019BChipsLittle Rock $           450
1/1/2019CIce CreamDenver $           300
1/1/2019CBeerDenver $           600
1/1/2019CPizzaDenver $        1,000
1/1/2019CChipsDenver $           200
1/1/2020AIce CreamNew York $           350
1/1/2020ABeerNew York $           450
1/1/2020AChipsNew York $        1,000
1/1/2020BIce CreamLittle Rock $           200
1/1/2020BBeerLittle Rock $           500
1/1/2020BPizzaLittle Rock $           450
1/1/2020BChipsLittle Rock $           350
1/1/2020CBeerDenver $           200
1/1/2020CChipsDenver $           100

 

To get the difference/ change between the revenue mix of 2019 and 2020, I created a measure "Diff_Mix_btw_Years_Store"

 

Diff_Mix_btw_Years_Store =

 

var _current_mix_ = DIVIDE(SUM(Store[Revenue]),CALCULATE(SUM(Store[Revenue]),ALL(Store[Store])))

 

var _previous_mix_ = DIVIDE(CALCULATE(SUM(Store[Revenue]),DATEADD(Store[Year].[Date],-1,YEAR)),CALCULATE(SUM(Store[Revenue]),DATEADD(Store[Year].[Date],-1,YEAR),ALL(Store[Store])))

 

return

 

CONCATENATE(FIXED((_current_mix_ - _previous_mix_)*100,1)," pts")

 

 

I returned what I need (B-A)

b_a.JPG

However, if I want to get the B-A value after replacing the row filter with either "product" or "location", I will have to create new measures and replace the Store[Store] in the above measure with Store[Product] or Store[Location]

 

d_p.JPG

Like this:

 

Diff_Mix_btw_Years_Product =
 
var _current_mix_ = DIVIDE(SUM(Store[Revenue]),CALCULATE(SUM(Store[Revenue]),ALL(Store[Product])))

var _previous_mix_ = DIVIDE(CALCULATE(SUM(Store[Revenue]),DATEADD(Store[Year].[Date],-1,YEAR)),CALCULATE(SUM(Store[Revenue]),DATEADD(Store[Year].[Date],-1,YEAR),ALL(Store[Product])))

return

CONCATENATE(FIXED((_current_mix_ - _previous_mix_)*100,1)," pts")

 

Is there any way to create one and the only measure that can return the result (B-A) for any row filter that users may apply? In this case, they are Store[Store] , Store[Product] or Store[Location].

 

I do not know if there is any DAX that can detect which column is used as a row filter and send to ALL( ) as a variable.

 

Please kindly help, thank you!

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

According to your description, I think you can simply modify your measure.

Like this:

measure =
VAR _current_mix_ =
    DIVIDE (
        SUM ( Store[Revenue] ),
        CALCULATE (
            SUM ( Store[Revenue] ),
            ALL ( Store[Store] ),
            ALL ( Store[Product] )
        )
    )
VAR _previous_mix_ =
    DIVIDE (
        CALCULATE ( SUM ( Store[Revenue] ), DATEADD ( Store[Year].[Date], -1, YEAR ) ),
        CALCULATE (
            SUM ( Store[Revenue] ),
            DATEADD ( Store[Year].[Date], -1, YEAR ),
            ALL ( Store[Store] ),
            ALL ( Store[Product] )
        )
    )
RETURN
    CONCATENATE ( FIXED ( ( _current_mix_ - _previous_mix_ ) * 100, 1 ), " pts" )

4.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

1 REPLY 1
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

According to your description, I think you can simply modify your measure.

Like this:

measure =
VAR _current_mix_ =
    DIVIDE (
        SUM ( Store[Revenue] ),
        CALCULATE (
            SUM ( Store[Revenue] ),
            ALL ( Store[Store] ),
            ALL ( Store[Product] )
        )
    )
VAR _previous_mix_ =
    DIVIDE (
        CALCULATE ( SUM ( Store[Revenue] ), DATEADD ( Store[Year].[Date], -1, YEAR ) ),
        CALCULATE (
            SUM ( Store[Revenue] ),
            DATEADD ( Store[Year].[Date], -1, YEAR ),
            ALL ( Store[Store] ),
            ALL ( Store[Product] )
        )
    )
RETURN
    CONCATENATE ( FIXED ( ( _current_mix_ - _previous_mix_ ) * 100, 1 ), " pts" )

4.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

 

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

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.