How to use rank with parameter & calculated field

Hi,

I have a parameter to switch between two field - sample size & z-score. I want the functionality to switch the parameter and the crosstab view should rank according to selection.

sample size is calculated field - distinct_count({id})

z-score is a calculated field consisting of avgOver & stdevOver…

both calc field works fine individually and provides the correct output, so nothing on that end.

But when trying to use rank(z-score) or rank(sample_size) I get error

Expression rank({Z-Score}) for function rank has incorrect argument type rank(Decimal). Function syntax expects Non-empty List, List, Calculation Level
Non-empty List, List
‘rank()’.

Expression rank({sample_size}) for function rank has incorrect argument type rank(Number). Function syntax expects Non-empty List, List, Calculation Level
Non-empty List, List
‘rank()’.

You need to rank the z-score or sample size by a list.

It should look like this.

rank([{Z-Score} DESC])

rank([{sample_size} DESC])

1 Like

Hi @Max ,

Thank you so much for providing the solution… I had one follow-up question… How can I sort using the rank calc field?
In the screenshot attached you’d see that rank 1,5,6,7,34,50 are clubbed together and then 2, 3, 4 comes… but in true sense I need 1,2,3,4,5…

In tableau when you use rank, I can move that over as the first column and it creates one row per record. I want something similar

You can sort based on that rank field.

Click on the field wells and select the rows you want to sort.

I would open up the sort options and plug in the rank and sort it on it’s average (makes sure that it sorts on the number of the rank)

I updated all the fields under rows field well to sort using Rank… like you mentioned

but the view is still the same (as the screenshot in my above question), multiple ranks clubbed together based on the first column.

Found the soln… had to convert it to standard table instead of pivot table then the sorting worked.

1 Like

So glad you found the solution @jemin. Thanks for letting us know!

1 Like