Last 7 days data calculation in Tableau

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Last 7 days data calculation in Tableau



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 needto 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.



Can someone help me out achieving this?




3 Answers
3



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



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





In this case will the current value of the parameter change everday automatically??
– Yousuf Sultan
Apr 28 '17 at 3:53





No, it is static and the user selects it each time.
– Bernardo
Apr 28 '17 at 14:52



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






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

make 2 or more post in bootsrap

Store custom data using WC_Cart add_to_cart() method in Woocommerce 3

React Native Navigation and navigating to another Screen problem