You're right, the data gets filtered out by prior conditions - this is because we iterate through our logical statements, and data meets a condition, then the next row is evaluated. You have stumbled onto an important calculation rule in Tableau - data can only exist in 1 place at a time - that is it can only evaluate to a single condition in a statement. If your calculated field exists in this format, Yesterday's data is filtered out of your "7 day" bucket, and the first 7 days are filtered out from "30 days" so that it is only returning 23 days of data, and so on. The only way to do this are:
1. To use a table calculation which takes a running total so that it adds up/down or across the table as needed, so that the 90 day bucket truly contains 90 days of data, or
2. To create 5 different calculations so that there is no data filtered out by prior conditions
Also, worth noting, simply performing arithmetic on 2 dates always defaults to days, so while I would use a datediff, you could just say:
"IF today() - [day] = 1 THEN "Yesterday" END"
and create a "Yesterday" bucket. I prefer to take the multiple calculation route, as there is usually a high degree of re-usability in this approach, and you can avoid the issue altogether. You would simply create the calculations and put measure values on text and measure names on your rows or columns shelf as needed. However, from your screenshot I can see you are already using Measure Names/Values elsewhere, so a single approach would be the way to go. As such, use your existing calculation, but click the dropdown next to the measure, select Quick Table Calculation, and use a running total.
Well, for one thing, your datediff for 7 days should actually be 6. Today is one of the days in the range. So Today plus 6 prior days will give you a range of 7 total days.
And you can't just expect 90 or 60 or 30 days to get you exactly to the same day-of-month in a prior month. Some months have 31, some 28... But if you want to go back exactly 30 days, just know where it could land in the prior calendar month. For 30 days, you really want to do datediff of 29. (Same principle as above.)
Now the reason youe ending date ranges are not cooperating is that your logic is creating buckets that end where the prior bucket starts. I think you can see that.
Are you looking to get the 90-day bucket to include not only those values that vall between 60-90, but all records in the 60s and in the 30s and in the 7s and in YESTERDAY? Your ELSE logic is not making that happen. Please confirm if that's what you really want to happen.
And if you want the 90 bucket to include the prior ones, Ben explained what to do.
I assume they are using a true 30/60/90 day trailing, else the language should change to 1 month/2 months/3 months, but you make a good point, yes. I was assuming he was using yesterday's data, but if there is data from today, you will need to subtract 1 from those values, as today's datediff would = 0, not 1.
that's correct. I want the 90 days to include yesterday, 7 days, 30 days, and 60 days. I'll try out ben's suggestion. thanks.
Thanks. I'm going to try this later today.
Using the running total quick table calculation on the measures and compute using "Trailing Date Range" worked perfectly. Thanks!
Thank you for your inputs. I'm facing exactly the same problem and have decided to work with creating 5 different calculated fields. However, I'm struggling with putting all the 5 into a single view. I need a graph that has "Yesterday, Today, Last 7 days, Last 30 days" on the y-axis and the corresponding values on the x-axis. Below is a screen shot (added two of the calculated fields as a sample)-
Can you please tell me how to make use of the 5 calculated fields and where to place them?