From the course: Tableau: Mastering Calculations

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Calculating complex intervals between two points in time

Calculating complex intervals between two points in time - Tableau Tutorial

From the course: Tableau: Mastering Calculations

Calculating complex intervals between two points in time

A few videos ago, when we discussed truncating dates, I promised you that we would write even more exciting calculations. So let's take a look at the following use case. I want to compare multiple quarters with each other according to their sales per calendar week. To do this, I need to calculate in which week of the relevant quarter a purchase was made. So I want to know the difference in weeks that have passed from the start of the quarter to the date of purchase. Let's create a calculated field and call it week number within quarter. We use the DATEDIFF function again. Our DATEPART in this case is week. And our start date is the first day of the quarter. This is why we start to nest functions. So let me break this function into several rows. That is not strictly necessary, but I like to do that because it gives my calculation more structure and makes it easier for myself and possibly for other colleagues to later understand what I've been doing here. Now we want to truncate the…

Contents