2

I am trying to divide values from the same pill in Tableau. Per my screenshot, the pill is named "Animals" & the grouped values within that pill are dog, cat, hamster & horse.

How can I divide dog by cat? How can I divide hamster by horse? How I divide cat by hamster? etc.

How would I create a calculation to show the desired values?

enter image description here

J A
  • 45
  • 8
  • 1
    could you please provide a sample output? – Fabio Fantoni Jan 12 '21 at 11:01
  • 1
    @AnilGoyal I have just added in another image to show the pill used – J A Jan 12 '21 at 13:41
  • @AnilGoyal the expected outcome is for there to be a table of numbers that are divided by each other to create ratios & no, I do not use Tableau prep – J A Jan 12 '21 at 13:53
  • See your expected results require pivoting of rows to columns, which is possible in Prep and not in tableau desktop/public. If you want I could show you a method how to do it in data source application then ilke excel, sql? By Expected results I mean what are the results in case of NULL/NA/division by 0. All this you have to take care of – AnilGoyal Jan 12 '21 at 13:57
  • @AnilGoyal It can be done in Tableau Desktop, yes, please show me. & in case of Null, I would like it to be blank or 0 – J A Jan 12 '21 at 13:58
  • @AnilGoyal Oh I misunderstood your answer. It cannot be done in desktop?:(Is there any other way to divide values from the same dimension? – J A Jan 12 '21 at 14:05
  • @AnilGoyal I am trying to replace the "Value" measure & it will not let me replace it with a count measure – J A Jan 12 '21 at 14:25
  • @AnilGoyal I just replaced the image – J A Jan 12 '21 at 14:47
  • @AnilGoyal Yes, that is – J A Jan 12 '21 at 14:55
  • @AnilGoyal Everytime I replace "Value" with "Count" in the calculation, it does not work – J A Jan 12 '21 at 15:02
  • @AnilGoyal Okay, once I do that, I get 0's for 1 column & all the other columns are blank – J A Jan 12 '21 at 15:09
  • @AnilGoyal & I converted it to discrete – J A Jan 12 '21 at 15:10
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227210/discussion-between-anilgoyal-and-j-a). – AnilGoyal Jan 12 '21 at 15:13

1 Answers1

0

Without the option of pivoting rows to columns available in Tableau Desktop, you have to manually create each of the desired ratio calculated field.

I have created a sample data by sampling 200 rows in a Programming language

Your created view is like this

enter image description here

Now create a calculated field for each of the desired ratio. say cat/dog like this

ZN(SUM(IF [Animals] = "cat" then 1 else 0 END))/ 
ZN(SUM(IF [Animals] = "dog" then 1 else 0 END))

Better use this field as discreet

Add this field to view you'll get desired ratios

enter image description here

AnilGoyal
  • 25,297
  • 4
  • 27
  • 45