Determining whether a number is even or odd in Tableau could seem a silly task, and indeed the software does not include a build in function for this purpose.
However, in the last few days I found it useful in two different cases, and I managed to do it in two different ways (Yes, today you get two tips at the price of one)! Let’s go!
Using the “Modulo” function.
The first dashboard of the deck is a jukebox-fied version of the official Lineup of the concert, through which you can listen to the songs selecting a date and an artist.
The artists are sorted by the hour of their shows, and I built them as lollipop charts with custom shapes.
But how to make them pop alternatively above and under the central line?
As a first step, I determined if the “Artist Order” field was even or odd, using the following calculation:
The “%” notation indicates the “Modulo” function, which calculates the remainder of division of one number by a second number.
Then, I used “!=0” to tell Tableau that if the reminder is different from zero, than the number is odd, otherwise it is even. I could have also used “=0”, inverting odd and even.
As a final step, I used that calculation to assign a value of “1” or “-1” to my Artist shapes, depending on the position of their shows in the “Artist Order” field being an even or odd number.
Using the “INT” function.
The “INT” function truncates results to the closest integer, getting rid of the decimals.
As a lunch-break challenge, coach Andy asked us to build a scalable stream graph, i.e. a stream graph that allows the user to choose the dimension by which the values are sliced, and always split into two halves the number of items of the chosen dimension.
Showing it is easier than describing it:
Check this amazing tip by Emily to know how to build such a stream graph.
In order to split the chart in two, I first assigned an Index to the items of the chosen dimension.
Then I told Tableau to show the negative value of Sales for the items with an even Index, and the positive value of Sales for the items with an odd one, using the following calculation:
Basically, I am telling Tableau to split the items in two sets, depending on whether the result of dividing the Index with the number is or isn’t equal to its corresponding integer. Of course, if it is the case then the number is Even, otherwise it is odd!
Rendez-vous tomorrow for another tip!