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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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