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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
sujitjena
Resolver I
Resolver I

How to use filter condition in a measure which in turn can be filtered based on slicer

Hi,

 

I am trying to create a measure with  Calculate and Divide  functions as below (where Table= Roll, Column = Cost Category)

CALCULATE(CALCULATE(SUM('Roll'[Dist Hrs]),'Roll'[Cost category]="Approved absence",' Roll'[Dimension]="Actual")/DIVIDE(CALCULATE(SUM('Roll'[Avg HC]),'Roll'[Dimension]="Actual",ALLSELECTED('Roll'[Cost category])),CALCULATE(SUM('Periods'[No of periods]),'Periods'[Dimension]="Actual")))

 

Basically, i have used one filter in the numerator Cost Category = "Approved absence". However, there is no filter in the Denominator. But when i try to use slicer on the cost category, it throws same value for all. Ideally it should give me the value after applying filter to the denominator. Any ideas if i am missing anything in the formula?

 

 

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

Hi @sujitjena ,

 

Do you have a relationship between 'Periods' and 'Roll‘? If so, the filter from slicer will also effect CALCULATE(SUM('Periods'[No of periods]),'Periods'[Dimension]="Actual")).

 

I suggest create a slicer table: table = VALUES('Roll'[Cost category]),  use it as slicer. As mentioned by lbendlin, use SELECTEDVALUE instead of ALLSELECTED in your formula. 

 

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

 

Best Regards,

Dedmon Dai

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @sujitjena ,

 

Do you have a relationship between 'Periods' and 'Roll‘? If so, the filter from slicer will also effect CALCULATE(SUM('Periods'[No of periods]),'Periods'[Dimension]="Actual")).

 

I suggest create a slicer table: table = VALUES('Roll'[Cost category]),  use it as slicer. As mentioned by lbendlin, use SELECTEDVALUE instead of ALLSELECTED in your formula. 

 

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

 

Best Regards,

Dedmon Dai

lbendlin
Super User
Super User

I put your formula through daxformatter.com,  but it still is hard to understand.

 

 

EVALUATE
CALCULATE (
    CALCULATE (
        SUM ( 'Roll'[Dist Hrs] ),
        'Roll'[Cost category] = "Approved absence",
        ' Roll'[Dimension] = "Actual"
    )
        / DIVIDE (
            CALCULATE (
                SUM ( 'Roll'[Avg HC] ),
                'Roll'[Dimension] = "Actual",
                ALLSELECTED ( 'Roll'[Cost category] )
            ),
            CALCULATE ( SUM ( 'Periods'[No of periods] ), 'Periods'[Dimension] = "Actual" )
        )
)

 

 

What's the rationale for the nested CALCULATE ?    Why " / DIVIDE "  instead of simple multiplication?  If you want to use a slider value then you need SELECTEDVALUE() somewhere. ALLSELECTED() is not enough.

Helpful resources

Announcements
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.