I'l Follio
I'l Follio

Reputation: 573

How to count aggregate function on Tableau

I have a calculate field (called TOTAL) on Tableau which is connected to R studio to create outputs through R (the R code is written inside the Calculate Field).

The R code has a function that returns a bunch of 100 and 50 in a function passing .arg's from Tableau, and the number of these will change if a given parameter changes.

This is the Calculate Field TOTAL content:

SCRIPT_STR("
    numbers <- function(a,b,c,parameter){
        a <- as.numeric(a)
        b <- as.numeric(b)
        c <- as.numeric(c)
        parameter <- as.numeric(parameter)
        al = ifelse(a > ((parameter * b) + b) | a < (c - (parameter * c)),'100','50')
        return(al)
    }
    numbers(.arg1,.arg2,.arg3,.arg4)
", SUM([A]),SUM([B]),SUM([C]),[PARAMETER])

Now, once I visualize the result (as example, in a Pie Chart), the chart doesn't tell how many 100's and how many 50's are, but it divides the number proportion through properly. Like this:

TOTAL result in Pie Chart TOTAL result in Pie Chart

Obviously the 100 in the first picture means one 100 of all the 100's that the output has, but I'd like to know the total of 100's and 50's

I tried to use COUNT over the TOTAL field, but it launches an error describing that TOTAL is already an aggregate function and it cannot be aggregated.

How can I solve this?

Upvotes: 0

Views: 1394

Answers (1)

Siva
Siva

Reputation: 9101

Try this process:

Create two calculated fields one for 100's and other for 50's

if Total = 100
then 1
else 0
end

For 50's count

if total=50
then 1
else 0
end

Now take the running sum for both the calculated fields and then place both formulas in tool tip.

Upvotes: 1

Related Questions