2
votes

I am having an issue in calculating last week data in Tableau. Below is my scenario:

In my dashboard, I have a slider which selects the date. In my table, I have a list of users where I will be showing each of them's call records. One column will have last week records and one will have total records.

For Total records, there is not an issue. But for finding last week's count, I need to have a calculated field, that needs to subtract 7 days from the date selected and then give out the number of records for each user.

Say I have selected date as 25-04-2017, then my table should show all the records until 25-04-2017 in one column and other should show data from 18-04-2017 till 25-04-2017.

3

3 Answers

3
votes

You can filter it with Relative days. When adding your dimension (date type) to the Filters list the picture below will appear.

enter image description here

Now you can click on the relative date and to choose the best option for you. You can see it in the picture below.

enter image description here

2
votes

Create a Date parameter for your user to select. Using the Superstore data set, I created a calc field for last 7 days sales:

if datediff('day',[Order Date],[date]) <= 7  and datediff('day',[Order Date],[date]) >= 0  then [Sales] end

And sales up to date:

if datediff('day',[Order Date],[date]) >= 0 
then [Sales] end

See attached example: https://www.dropbox.com/s/nqdp9zj74jay72d/170427%20stack%20question.twbx?dl=0

2
votes

I was able to find the solution for my issue. I created a boolean field as Max7Days with the formula as below:

DATEDIFF('day', [Date] , {MAX([Date])} ) <= 7

And created another that would count the number of records for the last 7 days if the condition was true as per the below formula:

CASE [Max7Days]
WHEN TRUE
THEN
[Number of Records]
END