Combine Multiple Modifiers in Formulas

Prev Next

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, make sure you already know all the different modifiers that can be used to change the Dimensions of formula items and how they work.

List of modifiers available in Pigment

MODIFIER

DEFINITION

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 of chaining modifiers? By chaining modifiers, you can work with different Dimensions 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.

'Your Metric'[modification 1][modification 2]

Option 2: Separate each modifier with a ";" within the same brackets.

'Your Metric'[modification 1; modification 2]

ℹ️ Note

For both of these options, the order matters: modification 1 is applied, then modification 2, and so on.

Example 1

Imagine we have a Metric Region Target with the Region Dimension.

We want to manipulate these targets with the following steps:

  1. Filter the Region Target Metric on EMEA only

  2. Allocate EMEA Target on corresponding EMEA Countries

  3. Allocate EMEA countries target on the Month Dimension

Without chaining Dimensions we would require three additional Metrics to do these manipulations.

  • EMEA target Metric with the filter:

  • EMEA Countries target with a first allocation on the Country dimension:

  • Monthly EMEA countries target with a second allocation on the Month Dimension:

ℹ️ Note

This works well, but you could do all these steps in one single formula with a single Metric!

  • With Option 1:

  • Or with Option 2:

Example 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 a breakdown of what is happening there:

  • We have a Metric Base Value Region with the Region Dimension

  • We allocate this Metric on the Month Dimension

  • We multiply it by another Metric which is 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, writing this formula:

'Region Target'[Add constant : Month, Product]

is the same as writing this:

'Region Target'[Add constant : Month][Add constant: Product]

The first one is shorter, and therefore better.

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 AVG, FIRSTNONBLANK or LASTNONBLANK in Remove or By aggregators.

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!

ℹ️ Note

Excel equivalent: none

Learn more

🎓 Pigment Academy

For detailed insights and video discussions on typical use cases and common pitfalls of each modifier by a Pigment Solution Architect, explore the Write and Test Formulas Learning Path in the Academy.