Optionally Partition Rules Based Allocation Using ForEachElementOf
Now that we have successfully written a Rules Allocation Dimension, we have the option to add another element to allow for a more nuanced allocation of cost.
The Problem to Solve
The cost formation language in the example up to now is sufficient for the majority of use cases. Previously, we allocated spend for a shared database relative to the cost of 3 products using the database. There may be instances where we want to allocate spend in a more nuanced way.
For example, let's say the shared database in the previous example is also shared across Development and Production environments. Each of our three products have some costs associated with Development, and some costs associated with Production. Rather than allocating the shared database costs by the overall proportions of SingleTenantProduct cost, we want to proportionally allocate spend to SingleTenantProduct by Environment as well.
Previously we were allocating the cost of the RDS Database to each product relative to that product's cost.
Our goal now is to allocate the cost of the RDS Database to each product relative to that product's cost by environment.
As we can see, $50 of spend shifted between Product B and Product C due to the higher relative ratio of Product C to Product B spend in Development.
Writing the Cost Formation Language
For the purposes of this exercise, we'll assume we've already created a dimension called
Environment
that describes the spend of Development and Production Environments.
We can add ForEachElementOf
to our existing dimension to achieve the desired effect above.
...
SplitDataLake:
...
ForEachElementOf:
GroupBy:
Source: User:Defined:Environment
Now our overall dimension looks like this:
Dimensions:
SharedRDS:
Name: Shared RDS
DefaultValue: Not Shared
Rules:
- Type: Group
Name: Shared Data Lake
Conditions:
- Source: Service
Equals: AmazonRDS
SplitDataLake:
Type: Allocation
Name: Split Data Lake
AllocateByRules:
AllocationMethod: Proportional
SpendToAllocate:
Source: User:Defined:SharedRDS
Conditions:
- Equals: Shared Data Lake
AcrossElements:
GroupBy:
Source: User:Defined:SingleTenantProduct
Conditions:
- Equals:
- Product A
- Product B
- Product C
ForEachElementOf:
GroupBy:
Source: User:Defined:Environment
Notice that under ForEachElementOf
we have used the GroupBy
shorthand to clearly express the logic. It is also possible to use the Groups
shorthand or the standard Rules
long form syntax. A full overview of how to write Rules Allocation Dimensions can be found here: Short Form Rules.
Link to Previous Step
Updated 7 months ago