Thanks to the Data + Tableau + Me website, we have the secret to get the perfect bar widths. Once you complete Step 2 and set the size mark to fixed, drag a parameter onto the size mark to make the units dynamic. This technique works for the calc/field as well.

When we tried this out for ourselves, we had the X-Axis as each day across the range of our data. As we change date levels, we plot the bar chart on the 1st day of the date level. For instance, the year would be January 1st, the month would be the 1st of the month, the week would be the 1st day of the week, and so on.

However, not all years have the same number of days, just like not all months have the same number of days. So, we adjusted the calc to tell us how many days are in each unit as the Date Level changes.

The new calculation is as follows:

The calc above finds the number of days in any year, quarter, month, etc… by taking the date difference in days from the date in question, and the next unit in line.

Here, the [DateSwap] changes our dates to the level configured in the parameter [DateLevel], and calculates the difference in days to give the correct number of days in a particular year, quarter or month (week and day also apply, however, those values are static).

Once we have that calc, our job is super simple. Change the size mark to fixed, and drag the size calc onto the mark.

In order for this to work, after you have put the Size calculation on the view, right click and set it to a continuous dimension.

And that's it!

You can expand on this however fits your needs. You can put Parameters on there for Marginal Histograms, or whatever other calcs you need, just make sure it's Continuous!

Now you can change Date Levels, and have pixel perfect width Bar Charts along the way! Play around with the dashboard below.

Tableau Software Inc. published this content on 03 January 2018 and is solely responsible for the information contained herein.
Distributed by Public, unedited and unaltered, on 03 January 2018 18:29:09 UTC.

Original documenthttps://www.tableau.com/about/blog/2018/1/how-make-perfect-bar-chart-widths-when-changing-date-80539

Public permalinkhttp://www.publicnow.com/view/F162FF211839F060C618DC635F26BE680648E295