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

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!

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!

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!

 

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"))

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.