By: Eric Parker
Eric Parker lives in Seattle and has been teaching Tableau and Alteryx since 2014. He's helped thousands of students solve their most pressing problems. If you have a question, feel free to reach out to him directly via email.
Tableau is a fantastic tool because of its flexibility, but it takes some time to master. Nowhere is this more evident than date calculations. Many of our most read blog posts deal with topics like comparing Month to Date vs. Previous Month to Date.
I was looking back over old posts and realized that I never wrote about comparing weeks. I am writing this post on August 26th, 2020 (Wednesday). Let’s imagine I want to compare this week to date (Sun-Weds) to last week to date. Here’s how we can do that.
I am going to use Superstore data for this demonstration and want you to first see that there are sales for each day of the year.
Now let’s say the question I am trying to answer is, “How is each category performing Week to Date vs. Previous Week to Date?”
I’m going to stay in the above worksheet while I build and test the calculations.
The first calculation will be calculating week to date sales.
If we add that as an additional column to the text table, we should only see sales values returned for days from this week.
The next calculation will be for sales from the previous week to date.
DATEDIFF ensures the data is from last week and the DATEPART function ensures the weekday isn’t later in the week than today’s date.
Once again, we’ll add the calculation as a new column in the text table to perform a test.
Now that we have ensured both calculations work, we are ready to calculate the difference between the two values.
We can calculate that difference as either a dollar value or a percentage.
Here is the calculation for finding the dollar value difference.
Here is the calculation for finding the percent difference.
After some number formatting, here are all the calculations combined in a single worksheet to help us answer our original question.
Want help with your own calculations or visuals? Book an upcoming office hour or shoot me an email!