# Dynamic Pricing
This secion covers using costs from a matrix and a target margin attribute value to create dynamic prices.
There is also some additional logic to make costs dynamic underneath the goal seek pricing behaviour.
Building on from the section on Prices and Costs this section will use a new attribute, product, matrix, expression set and pricing plan step.
Scenario: A product has a cost that varies based on whether it is shipped directly or via a third party. If it is shipped directly warehousing costs are added to the product, if it shipped via a thirdy party a marketing fee is to the cost. The price of this product is set based on a target margin %. This means the price will be dynamic based on the calculated cost and target margin.
Create a new attribute category called: Cost Management.
Now create a picklist and attribute called Distribution Method with values for Direct and Indirect.
Now create an attribute called Target Margin.
Clone the Field Guide - Attribute Object Type and create a new child called Field Guide - Attributes.
Now add the new Attribute to the layout.
Note that the Margin attribute is defined to be Run-time confiogurable and required. This means we will have an error in the cart until a value is defined. This is important as we have priced the product at 0!
### Create Target Price Product
Now add an arbitrary 0 price to One Time Cost. This is to ensure that the product is available through CPQ but will not be used in this scenario. The price and cost data will all come from the matrix.
### Create Matrix
Create a new Lookup Table (Decision Matrix) called ‘Field Guide - Target Margin Matrix’.
Upload the ‘Target Price Matrix.csv’ csv file on the matrix version and map the columns.
Activate the Matrix Version.
Create an Expression Set called ‘Field Guide Target Margin’. Click on the version record to open the Express Set Designer.
Define the rank for the ES Version.
Add a Lookup Table element and map it to the ‘Field Guide - Target Margin Matrix’ Matrix.
Add a resource per Pricing Variable and for Distribution Method and Target Margin. The Pricing Variable resources should have the same name as the Pricing Variable Code, the resources for the attributes we will be using are the Attribute name (without spaces). This will allow us to use the attribute values in our cost and pricing logic.
Add a branch to the Expression Set. We will set up one branch for Distribution Method (Direct) and one for Distribution Method (Indirect).
Under the Direct branch, create a calculation for each price and cost that defines cost as Warehousing Cost and defines price as Warehouse Cost with Target Margin.
Under the Indirect branch, create a calculation for each price and cost that defines cost as Marketing Cost and defines price as Warehouse Cost with Target Margin.
Run a Simulate to ensure that no calculations are left out of either scenario. There are six calculations expected for both Direct and Indirect.
Once everything is being returned activate the Expression Set version.
{"ProcedureName":"Field Guide Target Margin","MatrixName":"Field Guide - Target Margin Matrix","InputAttributeMap":"Distribution Method,Target Margin","DecisionMatrix":"true"}
Note: InputAttributeMap is used here to enabled the use of Distribution Method and Target Margin from the Express Set.
To Add: Store these costs against attribute values on the product
To Add: Use attribute rule to control visbility of target margin