cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sampak88
Regular Visitor

DAX formula with a filter value that is ignored from the report level

Hi,

 

I am trying to set up conditional colouring on a chart based on a measure.

I can do it with a:

AVGMost = CALCULATE(AVERAGEX(ALLSELECTED(table),table[Value]),ALL(table2[Category]))
this way I am ignoring the filter on the report level
what I am trying to do is set AVGMost to get that category fixed:
AVGMost = CALCULATE(AVERAGEX(ALLSELECTED(table),table[Value]),FILTER(table2, table2[Category]="cat1"))
and then apply this ias a conditional formating to see if any of the values from cat2 are below the average from cat1.
The result of the last one is when I filter on report to cat2 I get nothing colour coded as cat1 is filtered out and AVGMost = NULL
 
Also then I have a third category from table3[urban_level] on which I would like this calculation to accept this filtering from table3[urbal_level]
 
For conditonal colouring I have another measure with if condition to check if a value is greater or not - that part works fine.
 
Thanks,
 
sampak
1 ACCEPTED SOLUTION
RicoZhou
Community Support
Community Support

Hi @sampak88 

Your issue should be caused by ALL function in filter table '2016indx'. ALL function will make your code remove the filter from '2016indx' and due to relationship, your code will remove the filter from 'ZoneLookup' as well. So UR_NAME from ZoneLookup couldn't filter your measure. Try ALLSELECTED finction.

Measure = CALCULATE(AVERAGEX(ALLSELECTED(BUS),BUS[Value]),FILTER(ALLSELECTED('2016indx'),'2016indx'[Category] ="cat1"))

My Sample:

1.png

Relationship:

2.png

Result is as below. By default result is (1+2+3)/3 = 2. You see we can filter the Avg measure by UR_NAME from ZoneLookup.

(2+3)/2 = 2.5

3.png

Best Regards,
Rico Zhou

 

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

7 REPLIES 7
sampak88
Regular Visitor

@amitchandak - your formula is almost right, the only problem is that when I apply this table3 filter then the AVG calculated stays the same but I would like this to control the group of records. so for table3 cat1 the average is 5 and then for cat2 is 7 and the colour coding is dynamic just for that selection.

 

Thanks!

RicoZhou
Community Support
Community Support

Hi @sampak88 

Can you share a sample with us? You can show us the result you want by a screenshot. This will make us easier to understand your requirement.

 

Best Regards,
Rico Zhou

 

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

This formula is close:

CALCULATE(AVERAGEX(ALLSELECTED(table),table[Value]),FILTER(all(table2) , table2[Category]="cat1"))

however I have a third table connected that has a another category that should be filtering the AVG instead this remains static when I change the filter, see situation with no filter:

sampak88_0-1635330037400.png

and if I select it (the threshold for colouring remains the same as the average is):

sampak88_1-1635330054984.png

What I would like to have is the AVG being calculated to what the third table provides and the colouring being adjusted so the average is calculated on this subset only.

 

Thanks!

RicoZhou
Community Support
Community Support

Hi @sampak88 

I think you have created relationships between Table and Table2[Cagetory]/Table3[Cagetory2] . Does your relationship look like my Sample. In my sample Table has Category and Category2. 

1.png

In my sample this measure works well.

1.png

Result is as below.

2.png3.png

Best Regards,
Rico Zhou

 

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

 

 

Hey,

 

my relationship looks like this, where in fact the 1 to many in my queries is also 1 to 1

 

CALCULATE(AVERAGEX(ALLSELECTED(BUS),table[Value]),FILTER(all(2016indx) , 2016indx[Category]="cat1")) and then I want to filter based on UR_NAME from ZoneLookup

 

sampak88_0-1635415416068.png

 

Thanks!

 

RicoZhou
Community Support
Community Support

Hi @sampak88 

Your issue should be caused by ALL function in filter table '2016indx'. ALL function will make your code remove the filter from '2016indx' and due to relationship, your code will remove the filter from 'ZoneLookup' as well. So UR_NAME from ZoneLookup couldn't filter your measure. Try ALLSELECTED finction.

Measure = CALCULATE(AVERAGEX(ALLSELECTED(BUS),BUS[Value]),FILTER(ALLSELECTED('2016indx'),'2016indx'[Category] ="cat1"))

My Sample:

1.png

Relationship:

2.png

Result is as below. By default result is (1+2+3)/3 = 2. You see we can filter the Avg measure by UR_NAME from ZoneLookup.

(2+3)/2 = 2.5

3.png

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@sampak88 , if this measure is issues

 

try like

 

CALCULATE(AVERAGEX(ALLSELECTED(table),table[Value]),FILTER(all(table2) , table2[Category]="cat1"))



New Power BI Features
Datamarts: https://youtu.be/8tskWsJTEpg
Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!! !!
Dashboard of My Blogs !! Connect on Linkedin !! Proud to be a Super User!
Want To Learn Power BI
Learn Power BI Beginners !! Advance Power BI Concepts !! Power BI For Tableau User !! Learn Power BI in Hindi !!
!! Subscribe to my youtube Channel !!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors