2 Replies Latest reply on Feb 11, 2019 8:07 AM by Kaz Shakir

# CountD with condition

Customer_Id
Flag
1Y
1Y
1Y
2Y
3N
3N
4Y
4Y
4Y

I am a newbie,

I have a similar data table as above.

I need to do a CountD(Customer_Id) where Flag = 'Y'

IF ([Flag] = 'Y')

THEN

COUNTD([Customer_Id])

END

Cannot mix agg and non-agg error.

How to get this solved.

Thanks

• ###### 1. Re: CountD with condition

first welcome to tableau

the message is just telling you that countd is an aggregation function so flag needs to be aggregated  you can use attr([Flag])

Jim

If this posts assists in resolving the question, please mark it helpful or as the 'correct answer' if it resolves the question. This will help other users find the same answer/resolution.  Thank you.

• ###### 2. Re: CountD with condition

Chellappan,

Give this a try.  Create a calculated field that looks like this, let's call it "Y_OR_N":

Y_OR_N:

IF ([Flag] = 'Y')

THEN [Customer_Id]

END

And then create a second calculated field that just contains one function, like this:

COUNTD([Y_OR_N])

Does that accomplish what you want?

Kaz.