2 Replies Latest reply on Oct 12, 2018 3:43 AM by Suvi Ahlstedt

# Count of records with condition

Hi,

I´m quite new to Tableau and I´m trying to solve following problem and currently have no idea how to proceed.

I should get count of orders which contains two specific products, for example count of orders which includes both Juice and Lemonade (it doesn´t matter if order includes also something else but those two are required to include to same order).

Below is sample data and correct answer should be 2 (Orders 1 and 3) but how I can calculate similar in Tableau? Orders may have x rows with different products but only the combination of two specific products is desired.

My data is quite big and I have to use another dimension but order as row dimension.

OrderRowProduct
11Milk
2Juice
21Milk
31Juice
41Milk
51Milk
2Juice

• ###### 1. Re: Count of records with condition

Hello Suvi,

You can try below approach:

1. Lemonade = { FIXED [Order]: max(if [Product]="Lemonade" then 1 else 0 END)}

2. Juice = { FIXED [Order]: max(if [Product]="Juice" then 1 else 0 END)}

3. COUNT ORDER = COUNTD(if ([Lemonade]+[Juice])=2 then [Order] END)

• ###### 2. Re: Count of records with condition

Thank you Meenu!

Actually I had to change FIXED --> INCLUDE in order to get filters work properly but this was the logic I was searching for.