Pigment is a very powerful multi-dimensional tool and one of the reasons why is the way it can handle dimensions in formulas. To do this in Pigment we use modifiers. Before going forward, you should already know the different modifiers that you can use to change the dimensions of formula items and understand how they work.
Here is the list of the different modifiers available in Pigment:
|ADD||To add a new dimension to a formula item.|
|REMOVE||To remove a dimension to a formula item.|
|BY||To replace dimensions of a formula item based on a mapping property or metric. This would result either in aggregating or allocating data.|
|SELECT||To remove a dimension to a formula item while applying a filter at the same time.|
|FILTER||To filter on one (or several) items of a dimension. The FILTER modifier does not change the dimensions of the formula items.|
With these modifiers, you can handle all the transformations you need to manipulate your data. But did you know that you have the possibility to chain modifiers? By chaining modifiers, you can work with different dimensionalities within the same formula and it can save you some unnecessary block creations.
As you already know, modifications are performed within
 in Pigment. There are two ways of chaining them:
Option 1: Keep each modifier within its own brackets and concatenate them.
'you metric'[modification 1][modification 2]
Option 2: Separate each modifier with a "
;" within the same brackets.
'you metric'[modification 1; modification 2]
For both of these options, the order matters: modification 1 is applied, then modification 2, and so on.
Imagine we have a metric
Region Target with the Region dimension.
We want to manipulate these targets with the following steps:
- Filter the
Region Targetmetric on EMEA only
EMEA Targeton corresponding EMEA Countries
EMEA countries targeton the Month dimension
Without chaining dimensions we would require 3 additional metrics to do these manipulations.
EMEA targetmetric with the filter:
EMEA Countries targetwith a first allocation on the Country dimension:
Monthly EMEA countries targetwith a second allocation on the Month dimension:
This is working well, but you could do all these steps in one single formula with a single metric!
- With Option 1:
- Or with Option 2:
By chaining dimensions, you can write formulas that apply at different dimensionalities and reach a highly detailed level of customization.
Here is another example :
('Base Value Region'[add constant : Month] * 'Driver by Region & Month')[by constant: Country.Region][add split: Product]
Here is what happens there:
- We have a metric
Base Value Regionwith the Region dimension
- We allocate this metric on the Month dimension
- We multiply it by another metric which already defined on the Region and Month dimensions
- We allocate the result of this multiplication on the Country and on the Product dimensions
Special case: Chaining the same modifier
Now that we have seen that we could chain different modifiers you might be asking yourself what happens when you chain the same modifier.For example, you will notice that writing this formula :
'Region Target'[Add constant : Month, Product]
is the same as writing this one:
'Region Target'[Add constant : Month][Add constant: Product]
So usually, you will prefer to write the first one (which is shorter).
However, on some occasions, these two ways of writing the formula are not equivalent. That is the case, for instance, when you are using non-commutative aggregators like
LASTNONBLANK in a
Example with [By Average:] :
Let's take this metric as an example:
Here is what you get when using the following formula:
'Revenue per Ctry & Product'[by avg : Country.Region, Month.Quarter]
And here is the result of the second formula, and in this case, order matters:
'Revenue per Ctry & Product'[by avg : Country.Region][by avg: Month.Quarter]
Changing the aggregation order:
'Revenue per Ctry & Product'[by avg : Month.Quarter][by avg: Country.Region]
In this case, because there are some blank cells in the source metric, the average of all values is not the same as the average of averages, and the order matters. Of course, it would not have been the case had all cells been defined with a value.
So pay attention when chaining your modifiers!
Excel equivalent: none