BY Modifier

  • 18 May 2022
  • 0 replies
  • 234 views

Userlevel 4
Badge +3
  • Community Manager
  • 41 replies

Description

Returns an block(Metric or Property) with different Dimension.  Pigment’s BY modifier can be used to both aggregate or allocate data depending on the relationship between the dimensions used in the formula. 

 

Syntax

Syntax is similar when using for allocation or aggregation, the difference is when defining the method.

Source_block[BY Allocation method: mapping attribute 1, mapping attribute 2]

or

Source_block[BY Aggregation method: mapping attribute 1, mapping attribute 2]

 

Source_block[BY allocation method: mapping attribute 1, mapping attribute 2]

  • Source_block is the metric or list property that contains the values to be aggregated or allocated 

  • allocation method is where you define the way that values are distributed, this is an optional field. If it is not defined, values will be distributed by the Constant method

  • aggregation method is where you define the way that values are aggregated, this is an optional field. If it is not defined, values will be aggregated using the Sum method.

  • mapping attribute 1 is a list property or metric that defines the relationship between the dimensions in the Source_block and the dimensions in the target metric. The mapping attribute must have a dimension data type.  You must have 1 mapping attribute per use of the BY modifier. 

  • mapping attribute 2 is optional. This can be used when aggregating or allocation across multiple dimensions.

 

 

Return type

same as source object

 

Table of Contents 

What is a mapping attribute?

A mapping attribute is used to define a relationship between two lists. It can be either a property on one of the list or a metric using one of the list.  The critical element is that the property or metric has to be a dimension data type.   

For example, if you have a country and a region dimension.  You could use a mapping attribute to define how countries roll up to regions.  In order to do this, you must create a property or metric that is set to the dimension data type.  Here you can see an example from a Country list.  Because there are multiple countries within each region, you would set up the mapping property on the Country list. 

 

How do you set up allocation vs aggregation using BY?

The determining factor on if data is allocated or aggregated when using the BY modifier is the relationship established in the mapping attribute. One relationship type is called One-to-Many (displayed as 1->N).  This is where you have the value of one item that you want allocated across multiple items. The other relationship type is Many-to-One (displayed as N ->1). In this relationship, you have many items that are aggregated into one item. 

 

One-to-Many

One-to-Many relationships are established when one item has a connection to many items in the other list.  For example, one region, Europe, Middle East, Africa, (EMEA), has a relationship to many items in the country list, France, Spain, United Kingdom and Italy.  If my source data is at the region level and I want to display it at the country level, that would be the One-to-Many relationship. This is because each region’s data would be distributed to many countries. In this example, the BY modifier would use an Allocation method.

 

Many-to-One

Many-to-One relationships are defined by multiple items being aggregated into one item. Let’s use the same example as above, where we have multiple countries rolling up to one region. If my source data is at the Country level and I want to display it at the Region level, this would be a Many-to-One relationship.  In this example, the BY Modifier would use the Aggregation method. It would take the values from France, Spain, United Kingdom and Italy and aggregate them into the EMEA region.  

 

The BY modifier will either allocate or aggregate based upon how we are trying to transform the data.  If your source data is at the Country level and your formula is at the Region level, the BY modifier will aggregate those values. If your source data at the Region level and you want to calculate it at the country level, it will allocate the values. The default behavior for allocation is CONSTANT and the default behavior for aggregation is SUM. There are other methods below that you can use as long as you define them in the syntax. 

 

Allocation Methods 

 

Constant 

This method will take the value from the source metric or property and apply it to every item within the replacement dimensions. This is the default behavior if no allocation method is defined. 

Source_block[BY Constant: mapping attribute ]

 

Split 

This method will take the value from the source metric or property and distribute it evenly across the items within the replacement dimensions.

Source_block[BY split: mapping attribute ]

Supported Data Types - Number, Integer 

 

Aggregation Methods

 

SUM 

This method returns the sum the source values from aggregated dimension. This is the default behavior when using BY.

Source_block[BY: mapping attribute ]

Source_block[BY SUM: mapping attribute ]

Supported Data Types - Number, Integer 

 

AVG

This method returns the average of the source values from aggregated dimension.

Source_block[BY AVG: mapping attribute ]

Supported Data Types - Number, Integer 

 

MIN

This method returns the minimum value of the source values from aggregated dimension.

Source_block[BY MIN: mapping attribute ]

Supported Data Types - Number, Integer, Date

 

MAX

This method returns the maximum value of the source values from aggregated dimension.

Source_block[BY MAX: mapping attribute ]

Supported Data Types - Number, Integer, Date

 

FIRSTNONBLANK

This method returns the first non blank value of the aggregated dimension.

Source_block[BY FIRSTNONBLANK: mapping attribute ]

Supported Data Types - All Types 

 

FIRSTNONZERO

This method returns the first non zero value of the aggregated dimension.

Source_block[BY FIRSTNONZERO: mapping attribute ]

Supported Data Types - Number, Integer

 

FIRST

This method returns the first value of the aggregated dimension.

Source_block[BY FIRST: mapping attribute ]

Supported Data Types - All Types

 

LASTNONBLANK

This method returns the last non blank value of the aggregated dimension.

Source_block[BY LASTNONBLANK: mapping attribute ]

Supported Data Types - All Types 

 

LASTNONZERO

This method returns the last non zero value of the aggregated dimension.

Source_block[BY LASTNONZERO: mapping attribute ]

Supported Data Types - Number, Integer

 

LAST

This method returns the last value of the aggregated dimension.

Source_block[BY LASTBLANK: mapping attribute ]

Supported Data Types - All Types 

 

ANY

Returns TRUE if at least one aggregated item is TRUE, else FALSE.

Source_block[BY ANY: mapping attribute ]

Supported Data Types - Boolean 

 

ALL

Returns TRUE if all aggregated items are TRUE, else FALSE.

Source_block[BY ALL: mapping attribute ]

Supported Data Types - Boolean 

 

COUNT

Returns the number of aggregated items (BLANK cells are not included).

Source_block[BY COUNT: mapping attribute ]

Supported Data Types - All types

 

COUNTBLANK

Returns the number of BLANK items in the aggregated dimension.

Source_block[BY COUNTBLANK: mapping attribute ]

Supported Data Types - All types

 

COUNTALL

Returns the number of aggregated items (BLANK cells are included)

Source_block[BY COUNTALL: mapping attribute ]

Supported Data Types - All types

 

COUNTUNIQUE

Returns the number of unique values in the aggregated dimension (BLANKS not included)

Source_block[BY COUNTUNIQUE: mapping attribute ]

Supported Data Types - All types

 

TEXTLIST

Returns the list of aggregated text values, separated by a comma.

Source_block[BY TEXTLIST: mapping attribute ]

Supported Data Types - All types

 

Excel equivalent: none

See also: REMOVE

 

 


0 replies

Be the first to reply!

Reply