Skip to main content
Question

FILTER some data only when a condition is true.

  • June 11, 2024
  • 5 replies
  • 14 views

I want to filter based on a condition like this:

FILTER Color = 'blue' WHEN Shape = 'square'.

 

I'm having trouble creating a formula like this because what I have tried is filtering all instances where Color = 'blue', but I want to filter only for blue color when the shape is square.

I think this should be something very easy to do, but I'm having trouble.

 

Thanks in advance :)

5 replies

Hi,

I am not completely sure if I understand your question correctly, this could be a simple OR, i.e.

FILTER Color='blue' OR Shape !='square'; (this would filter out all squares that are not blue but leave all other shapes in). For more elaborate statements you can also use

FILTER (

CASE

WHEN shape='square' AND color ='blue' THEN 1

WHEN shape='round' THEN 0

WHEN shape='triangle' AND color='red' THEN 1

....

END) = 1;

BR

Stephanie

 


florian.mrkvi
Level 7
Forum|alt.badge.img
  • Level 7
  • 30 replies
  • June 12, 2024

" I want to filter only for blue color when the shape is square"

 

That would be done like this: FILTER Color = 'blue' AND Shape = 'square';

 

BR Florian


  • Author
  • Level 2
  • 2 replies
  • June 12, 2024

Hi Stephanie and Florian,

 

I have tried using the AND condition but is filtering both conditions. For this example: FILTER Color = 'blue' AND Shape = 'square'; it's filtering all the color=blue and shape=square. But it should only filter blue when shape is square.

 

Let's take as example the following table:

 

image.pngThe desired output is the following:

image.pngWhat I'm getting with FILTER Color = 'blue' AND Shape = 'square':

image 

Thanks,

Julio


Hi Julio,

according to your example you have a wrong understanding of what FILTER does. It is positive, i.e. FILTER shape='square' will filter for squares only and triangle will be EXCLUDED. In the above example

FILTER shape != 'square' OR color !='blue' will result in the desired output.

BR

Stephanie


dxb.miner
Level 5
  • Level 5
  • 13 replies
  • October 25, 2024

@julio.bolan12 

Try below formula ,

 

FILTER shape != 'square' OR ( shape = 'square' AND  color !='blue' )