10 Replies Latest reply on Nov 18, 2016 4:49 PM by Shawn Wallwork

# Educational Brain Teaser: Understanding Calcs #1

The primary purpose of this post is NOT to challenge my Zen/Jedi brethren. But to challenge those finding calculations & Tableau syntax difficult. Let's see if this helps.

Here's the calc:

You need to know that [Clinton] and [Trump] are two separate measures. So here are my questions:

1. Will this calc result in a Measure or a Dimension?
2. Why use the ABS()?
3. Why does the calc assume everything else is 'Trump'?

Bonus: The first line tests the margin of error, what is the +/- error?

--Shawn

• ###### 1. Re: Educational Brain Teaser: Understanding Calcs #1
1. Will this calc result in a Measure or a Dimension?

RK: This will result in discrete measure

1. Why use the ABS()?

RK: ABS is to calculate the absolute value. The result will account only for numerical difference and doesnt accounts for + or -.

1. Why does the calc assume everything else is 'Trump'?

RK: If the Margin of Difference is > 5% and Clinton- Trump difference is negative then Trump is winning.

• ###### 2. Re: Educational Brain Teaser: Understanding Calcs #1

Shawn,

I love this as a great way of teaching!  One point of clarification:

you said,

You need to know that [Clinton] and [Trump] are two separate measures.

It actually wouldn't matter if Tableau had those two fields listed as Dimensions or Measures.  It does matter that they are numeric.  And, to determine the correct answer for your first question, it matters if they are row-level values/calculations or aggregate calculated fields. In the later case, Rekha Kesavan is exactly correct, but the answer could be different in the former case.

Best Regards,

Joshua

• ###### 3. Re: Educational Brain Teaser: Understanding Calcs #1

1) Could be a Dim if both [Clinton] and [Trump] are at the Row-Level

2) Difference could be +/- on both sides.

3) 'cause it looks like [Trump]-[Clinton] > 0.25 covers the rest.

But, the strict calc would be like this:

IF ISNULL([Clinton]) OR ISNULL([Trump]) THEN 'Not enough data'

ELSEIF ABS([Clinton] - [Trump]) <= 0.05 THEN 'Tie'

ELSEIF [Clinton] - [Trump] > .025 THEN 'Clinton'

ELSE 'Trump'

END

• ###### 4. Re: Educational Brain Teaser: Understanding Calcs #1

Note to all my Zen/Jedi brethren: OK, so rewrite this Teaser to better teach what I was attempting to teach (and obviously failed to do).

--Shawn

PS: And also come up with your own Educational Brain Teasers (EBT), of a similar ilk. The idea is to challenge beginners/intermediate Tableau users to understand calculations and syntax. I look forward to your EBTs!

• ###### 5. Re: Educational Brain Teaser: Understanding Calcs #1

Having just reread this thread, I've come to the conclusion that there really isn't a way to pose beginner/intermediate EBT questions on this forum. I was hoping this would be a Sudoku easy-medium-hard type of thing. But now I see the pitfalls. Oh well, I tried.

Cheers,

--Shawn

• ###### 6. Re: Educational Brain Teaser: Understanding Calcs #1

Shawn,

I'm not sure you should give up so quickly.  Overall, I think this could be effective.

What I might suggest is a bit of context and foundation.  E.g. What exactly are dimensions and measures?  Discrete and continuous? Row Level and Aggregate?  Those are among the foundational concepts that I wish I'd known when I started using Tableau. With those in place  you'd maximize the impacts of asking the questions you have above.  And of course, the variations on how things can be done and alternate methods for writing calcs, etc... is a valuable learning experience in and of itself (though, I understand, not the primary goal of what you are doing here).

Best Regards,

Joshua

• ###### 7. Re: Educational Brain Teaser: Understanding Calcs #1

It would be working (to an extent)

if Qs could be formatted as a short Quiz.

but taking a Quiz, one could.

And of course it would be a bar chart aggregating

everybody's Answers -- and the right ones,

which could not be the same after all.

• ###### 8. Re: Educational Brain Teaser: Understanding Calcs #1

It actually wouldn't matter if Tableau had those two fields listed as Dimensions or Measures.  It does matter that they are numeric.

Have you ever seen ABS() used on anything that wasn't numeric? Or would Tableau allow you to create a calc that did a boolean test of a string against a number? So my question is: Could those two fields be anything other than numeric? And since the 'results' of the calc are going to be a string Tableau will automatically classify the calc as a dimension, yes?

I get that I didn't totally account for the fact that the user could drag it to the Measures window, which is the finer point that I missed, and you pointed out. So I should have asked: "Will the default calc result in a dimension or a measure?" (I probably should have not asked that question at all.)

I asked the second question because I first (stupidly) structured my calc like this:

IF [Clinton]-[Trump] <= .025  AND [Clinton]-[Trump] >= - .025 THEN ....

My intended point was to always look for better ways to accomplish your goal in a simpler fashion. Using ABS() is much simplier.

Finally my third question was intended to point out that once any condition proves 'True' the calc falls to the end and the subsequent lines of code are not executed. This can be both helpful, and confusing.

Rekha, you essentially got most everything right. Even though my 'test-design' skills were very much lacking.

Cheers,

--Shawn

• ###### 9. Re: Educational Brain Teaser: Understanding Calcs #1

FYI: The plus/minus error is 2.5% (.025), not 5% (.05).

--Shawn

• ###### 10. Re: Educational Brain Teaser: Understanding Calcs #1

What I might suggest is a bit of context and foundation.  E.g. What exactly are dimensions and measures?  Discrete and continuous? Row Level and Aggregate?  Those are among the foundational concepts that I wish I'd known when I started using Tableau. With those in place  you'd maximize the impacts of asking the questions you have above.

Joshua I completely agree. Would you be so kind as to structure an EBT that demonstrates the concepts and attributes that you think would be most educational? I will be happy to follow your lead -- following the Q&A format you set out.

This will be cool!

--Shawn