Tableau Benfords Law chart

This article explains how to create and use the Tableau Benfords Law chart with a practical example. The Benfords Law chart is a mathematical law that helps to check whether the data is real or fake. It takes the first digit or the leftmost digit and draws the bar chart. If the data obeys the Benford Law, 1 appears around 30%, and 9 appears less than 5%; if true, it is accurate data.

To demonstrate this Tableau Benfords Law chart example, we used the Sample Superstore Excel sheet. Please visit the Excel Source article to understand the Data Source.

Tableau Benfords Law chart

First, create a calculated field to write the expression. To do this, right-click the empty space within the Measures shelf to select the Create Calculated Field.. option. Otherwise, use the Analysis Menu option.

The expression below uses the LEFT string function to return the first or leftmost digit of the sales measure. Here, the STR() function converts the Sales to the string, and the Tableau Benfords Law chart uses it to draw the bar. For remaining functions >> Click Here!

LEFT(STR([Sales]), 1)

Drag and drop the Count of Orders Measure to the Rows shelf and the newly created LeftValue calculated field to the Columns Shelf. By default, it creates a column chart. If so, please change the mark type from Automatic to Bar. For the remaining charts in Tableau, please click here.

Bar Chart with left digits

We don’t need the 0 columns to create a Benford Law chart. So, add the LeftValue calculated field to the Filters Shelf and remove/uncheck 0 from the list.

Remove 0s using Filters shelf

Use the T button in the toolbar to add the data labels to the Tableau Benfords Law chart.

Add Data labels to Tableau Benfords Law Chart

It displays the total orders. However, we need the percentage of the total in the Tableau Benfords Law chart. So, click the down arrow beside the CNT(Orders) in the Rows shelf, choose Quick Table Calculation, and select the percentage of the total. Please refer to the Quick Table Calculation and calculate the percentage of total articles.

Quick Table Calculation to find the percentage of total

Now, you can see the percentage of totals. Let me create one more calculated field to write the Benfords Law expression.

Tableau Benfords Law Chart with Percentage of Total

The Tableau expression below calculates the Benfords Law. Please search the internet to understand the formula.

LOG(1 + 1/ INT([LeftValue]))

Please add the Tableau Benford Law calculated field to the details shelf; otherwise, you can’t use it in the reference lines. Next, right-click on % of total orders Axis (Y-Axis) and choose the Add Reference Line option.

Add Reference Lines to Tableau Benfords Law Chart

It opens the following Add Reference Line, Band, Box, or Distribution window. Please use this window to add reference Distribution to the Bar chart. First, let me choose the per cell scope value as the 80%, 100%, and 120% of Average. Here, choose the MIN(Benford Law) calculated field as the percent of option. Once you choose them, you can also notice the gray and white smoke lines in the report.

Choose Reference Distribution

Under the Formatting section, choose the spotlight color to fill below and above the distribution.

Checkmark Fill Above and Below to Add Colors

As there are some white lines in the Tableau Benfords Law chart, let me use the Format menu to remove the Grid lines, as shown below.

Tableau Benfords Law Chart with Reference distribution line

Suppose you add the Category dimension before the Order count. In that case, the Tableau desktop displays the Benfords Law chart for each category.

Multiple Tableau Benfords Law Charts

You can experiment with the same by replacing the Category with Segment.

Tableau Benfords Law Chart preview