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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

CALCULATE conditional filters for specific circumstances

Lets say I had a table like below:

 

ActionDuration (minutes)EvaluationFactor AFactor B
Running20GoodYes 
Jumping jacks12BadYes 
Running19Okay  
Jumping jacks11Great Yes
Jumping jacks115Superb Yes
Running412BadYes 
Jumping jacks0Good Yes

 

I have a DAX formula below that is meant to average the Duration field, excluding rows where the Evaluation is "Bad", Factor A is "Yes", and/or Factor B is "Yes."

 

Duration Average = CALCULATE(
AVERAGE('Table'[Duration (minutes)]),
'Table'[Evaluation] <> "Bad",
'Table'[Factor A] <> "Yes",
'Table'[Factor B] <> "Yes"
)

 

Lets say that for Jumping Jacks, I do want to include rows where Factor A is "Yes" and/or Factor B is "Yes." For running, I want to exclude rows where Factor A is "Yes" and/or Factor B is "Yes."

 

Is there a way that I can adjust this DAX formula so it only excludes Factor A and Factor B for "Running" rows?

 

It would be simple to write two separate DAX formulas, but my boss wants me to create a table that looks like this:

 

Action                                        Average Duration

Jumping jacks 
Running 

 

The only way I can figure out to have one column for average Durations is to have a single DAX average formula. 

 

Another alternative I thought of was using Power Query to remove running durations with Factor A and/or Factor B, but my boss does not want me to use Power Query to alter the table in that way.

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your logic correctly, but please check the below picture and the attached pbix file.

 

Untitled.png

 

Avg duration with the condition measure: =
AVERAGEX (
    FILTER (
        Data,
        SWITCH (
            TRUE (),
            Data[Action] = "Running",
                Data[Factor A] <> "Yes"
                    && Data[Factor B] <> "Yes",
            Data[Action] = "Jumping jacks",
                Data[Evaluation] <> "Bad"
                    && OR ( Data[Factor A] = "Yes", Data[Factor B] = "Yes" )
        )
    ),
    Data[Duration (minutes)]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your logic correctly, but please check the below picture and the attached pbix file.

 

Untitled.png

 

Avg duration with the condition measure: =
AVERAGEX (
    FILTER (
        Data,
        SWITCH (
            TRUE (),
            Data[Action] = "Running",
                Data[Factor A] <> "Yes"
                    && Data[Factor B] <> "Yes",
            Data[Action] = "Jumping jacks",
                Data[Evaluation] <> "Bad"
                    && OR ( Data[Factor A] = "Yes", Data[Factor B] = "Yes" )
        )
    ),
    Data[Duration (minutes)]
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

Thank you!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

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.