Search

# How to Calculate the 7 Day Moving Average in Tableau Using Table Calculations

How do you calculate seven day moving average in tableau in this example I have a bar chart of quantity by date and I have a line chart in blue overlaying the bar chart with the seven day moving average let’s see how to do this in tableau. In order to calculate seven day moving average we’re going to need a date I’m going to bring it in as day of date. To change this to the exact day continuous I’m going to bring in quantity to make a bar chart. Let’s change it to a bar. Next we’re going to want to copy the quantity pill so let’s take the quantity pill and put it up onto rows next to the first quantity to get a second axis now click on the drop down on sound of quantity choose a quick table calculation and choose moving average. At this calculation by choosing the drop down clicking edit table calculation and I’m going to adjust this so I want it to be the seven day moving average so I’m going to say the previous seven days obviously it’s average although you can use some minimum maximum and I want to exclude the current value so for every bar Tableau is going to calculate the average of the previous seven not including the current bar so one two three four five six seven all of these will be included in this value let’s change this quantity to a line. And create a dual axis by clicking on the drop down and selecting dual axis. Now we have a moving average over my bars this is actually a calculation so you can copy this entire calculation out of The View and put it into a calculated field and call this moving average. The calculation is simply window average sum of quantity comma minus seven comma minus one click ok.