how can i compute relative change across previous months with multiselecet month filter

19 Views Asked by At

I have a list of KPIs and a multiselect year and month filter. I want to display the changes in the KPIs with respect to the previous months.It's easy to show the change across one previous month(for example, Jan to Feb or Dec to Jan).

However, If the user selects two months from the multiselect filter, then it becomes challenging to find the change. For instance, if the user selects Feb and Jan together, how can I modify my calculation to get the change in that case?

1

There are 1 best solutions below

0
Alex Blakemore On

Are you using a table calc to calculate the change from prior period? That is usually how you'd do this in Tableau.

If so, you typically start by making a "quick" table calc, just by right clicking on a measure field, say SUM([KPI]), then selecting a preset table calc from the context menu -- such as Difference. In the case of Difference, you can then use the context menu again to specify what the difference is "Relative To", i.e. first, previous, next, or last.

A key part of defining a table calc is to also specify how to traverse the underlying table of summary results, by specifying the partitioning/addressing fields, aka "compute using". That also, can be specified from the context menu.

The "quick" table calc is really just a shortcut for writing a calculated field that calls some of the Table Calc functions, such as LOOKUP(), WINDOW_SUM(), INDEX(), SIZE() etc.

So if you are using a quick table calc, drag it to the data pane on the left margin to materialize the calculation into a named field. Edit the calculation to see (and change) how it operates. The quick table calcs are just fast menu shortcuts for the common cases. For comparison, you may be using the function LOOKUP() which takes an offset as an argument. If you want the offset to be flexible, use a parameter or a calculated field for the offset instead of a constant.

Table calcs are useful, but mysterious until you take the time to learn how they operate. Read the help documentation about them. Start with the simple functions to understand them - INDEX(), SIZE(), FIRST(), LAST(), WINDOW_XXX(), LOOKUP(). Then experiment with the edit table calc dialog to understand how partitioning and addressing impact behavior.