***************************************************** ***************************************************** ***************************************************** ***************************************************** ***************************************************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** This Confluence article was automatically generated from Asciidoc. Any changes you make to this document will be overridden! If you want to change the content, consider leaving a comment. You can edit the content directly here: https://gitlab.pricefx.eu/training/pricefx-knowledge-base/-/tree/dev/public/content/docs/concepts/price-lists/matrix-price-lists ***************************************************** ***************************************************** ***************************************************** ***************************************************** ***************************************************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING ********************** ********************** WARNING **********************

"As a Pricing Manager, I want to be able to pre-calulate regional online prices for products in all different volume tiers, so that we can publish all the prices already precalculated."

Generally, the use case covers many scenarios, where a single product can have multiple prices, for various:

  • Region/Country — The product is priced differently in different parts of the world.

  • Customer — Different customers pay different prices.

  • Volume Tiers — The price per product gets lowered as one purchases more items.

Solutions

Generally there are several solutions to how to implement this in Pricefx:

  1. Multiple Price Lists — For example, there could be one Price List for France and another separate Price List for Germany. To identify which country the Price List is created for, there are several options:

    • Naming convention of the Price List name — for example, the name of the Price List could contain the ID of the customer.

    • Price List column holding the parameter value for which the price varies over — for example, if the price varies for different customers, a new Price List could be created for each customer and a column in the Price List would contain the customer ID. All the cells in this column would contain the same value.

      SKU Customer Id List Price

      MB-0001

      CD-00001

      4,74 €

      MB-0002

      CD-00001

      17,60 €

      MB-0003

      CD-00001

      21,36 €

      …​

      …​

      …​

    • Customer assignment - A Price List can be assigned to a specific customer (but only after it has been created). This is a special use case that only works when the prices vary for different customers, i.e., it could not be used for country Price Lists.

      pricelist assign to customer button
  2. Create a Regular Price List, where one line will hold more prices for single SKU - prices for different regions/tiers are in different attribute collumns. You are limited to 100 attribute columns here, but it’s enough in most cases.

  3. Create a Matrix Price List, where each SKU can appear repeatedly on multiple lines in the same Price List, each time for different customer/region/tier etc.

What is a Matrix Price List

A Matrix Price List is a Price List with two keys:

  • Primary key: SKU

  • Secondary key: Any other dimension such as country, quantity tier, customer id, etc.

Each product can appear on multiple rows in the same Price List. Each combination of the sku + secondary key has to be unique.

If more than two keys are needed, for example a combination of SKU + Region + Tier, you can concatenate the values of Region and Tier and use the concatenated value as the 2nd key.

Example

In the example below, the Volume Break is a secondary key.

PriceGrid Final

Different products have different volume breaks and different discount. The prices are calculated based on the combination of the SKU and Volume Break.

The Volume Breaks could be defined in a Pricing Parameter:

Product Group Volume Break Volume Discount

Meatball

VB-001

1

0 %

VB-005

5

3 %

VB-020

20

8 %

Sausage

VB-001

1

0 %

VB-005

5

2 %

How to Implement Matrix Price List

In order to be able to implement Matrix Price List, the following needs to be prepared in the partition:

  • Matrix Logic - Calculates values for the secondary key.

  • Price List Logic - Price List Line Item logic which calculates results based on both - SKU and SecondaryKey values.

When the business user creates a new Price List definition, the following needs to be specified in the Set Parameters steps:

  • Matrix Logic — A reference to the Matrix Logic.

  • Matrix Logic Element — The element.

image 2020 09 02 14 28 48 718

For the next code demonstration, we will expect the following Company Parameter

PriceParameter VolumeTiers

Process of Execution

When the user starts the calculation, the Calculation Engine leverages both logics in certain order. Review the diagram to understand the flow of execution of the two different logics used in the Matrix Price List process.

matrix pricelist process.drawio

Matrix Logic

Is a standalone logic, which provides values for the Secondary Key column of the Price List for one particular SKU. It’s executed by the system each time, when the system adds new SKU into the Price List. The system places the SKU, for which it needs the list of secondary key values, into the Context, and then it executes the Matrix logic. So the Matrix logic can simply read the SKU from the Context or use API functions, which use the information implicitly.

The logic element, which returns the list of values, must have DisplayMode set to either “Price Lists” or “Everywhere”. The element to be used for the Price List, will be set up by the business user while creating the Price List.

To create a new Matrix logic:

  1. In IntelliJ, on the Project tool window, right-click on the project name and select Pricefx  Create Calculation Logic:

    MatrixPL CreateLogic
    1. This will generate an updated formulaNature value:

      MatrixPL FormulaNature
  2. Next, we would need to identify the value that will be used for the secondary key of the matrix. For example, if based on the Region and Business Unit there was a volume breakpoint defined in a company parameter table:

    def region = input.Region                               //❶
    def businessUnit = api.product("BusinessUnit")          //❷
    
    if (region != null && businessUnit != null) {
    
        def volumeBreaks = api.findLookupTableValues("VolumeBreaks", "VolumeBreak",
                Filter.equal("Region", region),
                Filter.equal("BusinessUnit", businessUnit)
        )?.key3
    
        return volumeBreaks                                 //❸
    
    } else {
        api.throwException("Region was not specified or product's Business Unit not found.")
    }

    ❶ Input value was entered by the business user during preparation of the Price List (the value is passed to the Matrix Logic via context).
    ❷ We can use the value of SKU, because it’s provided in the context.
    ❸ Return the list of values for the secondary key.

Price List Logic Leveraging the SecondaryKey Value

The use of the api.getSecondaryKey method is the same as using api.currentItem("key2") (just remember, that api.currentItem() works only, when the item already exists) and it retrieves the secondary key field (in this case "key2") of a "matrix record" - it is a standard Price List line item logic and used to calculate the results based on the combination of the SKU and SecondaryKey.

The value of the SecondaryKey is only available for execution in the Price List / LPG and not when testing the logic in Studio. So for testing purposes, we will create one additional input (which will only be available in Studio):

if (!api.isDebugMode()) {

    return api.getSecondaryKey()                                    // ❶

} else {

    if (api.isInputGenerationExecution()) {
        api.option(                                                 // ❷
            "VolumeBreak",
            api.findLookupTableValues("VolumeBreaks", "VolumeBreak")?.key3?.unique()
        )
    } else {
        return input.VolumeBreak
    }

}

❶ Reading the value of SecondaryKey column of the line item, only works in "real" execution.
❷ So, during testing phase, we build additional input, so that you can select the value of Volume Break manually.

Additional Setting while Creating a New Matrix Price List

When the business user creates new Matrix Price List, they need to select both the Matrix logic and Matrix Element. Below, we show how at Price List creation time the Price List type of MATRIX is selected:

NewGrid Step1

As we continue to define the PL parameters, we can define the matrix logic and the logic element. In the following example, the setting specific for matrix will be:

  • Matrix logic: "PG_MatrixPriceGrid_Matrix"

  • Matrix logic Element: "Volume Breaks"

NewGrid Step3

Let’s describe here the most important parameter values defined on this panel:

Built-in Input Parameters
  • Dynamic item mode: Add & remove. The requirement was to have the list of products in sync with the products available in the Product Master.

  • Default pricing logic: PG_MatrixPriceGrid. This is your line item logic.

  • Matrix logic: PG_MatrixPriceGrid_Matrix. This is your matrix logic, which will supply the values for secondary keys.

  • Matrix logic element: Volume Breaks This is the element, which actually returns the list of values.

  • Result Price: List Price

Custom Input Parameters
  • Region: Europe. This input is created by the line item logic, and the user will select here, for which region are the prices in the LPG used.

Outputs, which are mapped to the Price List Line Items
  • Output Elements: Select all your visible elements of the line item logic, the customer wants to see all the intermediate results.

After calculation, the final “Matrix” Price List could look like this:

PriceGrid Final

References