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])
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.
Give this a try. Create a calculated field that looks like this, let's call it "Y_OR_N":
IF ([Flag] = 'Y')
And then create a second calculated field that just contains one function, like this:
Does that accomplish what you want?