问题
Im trying to create a wiondow average calculation of 3 months using "window_avg" function. So far every month(viewing from the right) I get the correct window average. However If i filter down using the order date to 1st November to End of Date, then Im not able to get the correct average for December 2015.
What Average Im supposed to Get for Dec 2015 when Order date in filter is 1st Nov to End of Date: (31045 + 75973 + 74920)/3 = 60766
What Average Im getting for Dec 2015 when Order Date in Filter is 1st Nov to End of Date : 75446(Here instead of window average for 3 months it takes wondow average of 2 months)
So the question is : How can i make sure that even If I filter the values I get the correct window average of 3 months and not based on the filter criteria?
Workbook Link Here
I know that table calculations are based on what is in the view, but still is there a workaround for the same ?
回答1:
Set your filter to include all the data you want included in your table calc — that is, filter to include any prior months needed in data you want to display. So if December 2017 is the first month you want to display, and if your moving average requires 2 prior months, filter to start in Oct 2017.
Then right click on the headers and ‘hide’ the months you don’t want to display.
Table calcs are computed in Tableau based on the result set returned by the data source in response to Tableau’s query. Filters — other than table calc filters - control what data is included in the query result. Hiding marks just prevents them from being displayed.
The example below does effectively the same thing as described above, but uses parameters and a table calc filter to avoid having to manually hide marks. The calculated field [Within Date Range] is defined as [Order Date] >= DATEADD('month', -2, [Start Date]) and
[Order Date] <= [End Date]
and [Start Date] and [End Date] are parameters.
Be sure to notice the filter based on the index () function. Table calc filters hide values, rather than exclude them from the results.
Here's another variation
来源:https://stackoverflow.com/questions/48746209/need-to-take-window-average-of-last-3-months-for-my-sales