1
votes

so i want to put calculate field, if the contains selected product, then it appear number of count order (id for transaction) of that product (on this case, using count distinct for order_match_id (its the id for every transaction)

im using this

 IF CONTAINS([Selected Product], [Name])
THEN (CNTD([Order Match Id])
ELSE NULL
END

but its says Expected Closing paranthesis for the expression starting at characted 47

the point is, i want to make some else if condition, if the condition true, then appearing count distinct of id transaction to provide how many transaction

2
you have an extra "(" in the second line, between then and cntdFabio Fantoni
do you mean? IF CONTAINS([Selected Product], [Name]) THEN ((CNTD([Order Match Id])) ELSE NULL END ?18Man
if that, then its still same erorr sir18Man
or do you mean THEN CNTD([Order Match Id]) ? if so, then its unknown function CNTD called18Man
you have multiple problems: 1) cntd is not a Tableau functions since you should use COUNTD; 2) you're aggregating inside an if statement based on non-aggregated valueFabio Fantoni

2 Answers

2
votes

Even though you may want to add more logic to your statement, you should remember that you cannot mix aggregated with non aggregated values.

Basically, your formula should be more like this:

COUNTD(IF CONTAINS([Selected Product], [Name])
THEN [Order ID]
ELSE NULL
END)

Doing so, "first" you test your condition for each row and "then" you aggregate values using COUNTD (not cntd)

0
votes

after posting this question on tableau community, this is the best answer so far

they are probably not the right dimensions but see the use of atta and countd

IF CONTAINS(attr([Kategori]), attr([Name]))

 THEN COUNTD([Order Match Id])

 ELSE NULL

 END