Sub topic 12
Allocating Values with Weight Columns
This chapter assumes you have already built a bridge table of unique AccountID and CustomerID pairs. It also assumes you know how the bridge relationships are wired, and that you can write measures with SUM, CALCULATE and SUMX. It covers how to add a weight column to the bridge so each shared account's amount is split across its customers instead of being counted in full for each one.
The problem a weight solves
A bridge table makes a many-to-many model filter correctly. It does not change the arithmetic. If account A1 has 1,000 in transactions and is shared by Ann and Ben, a report by customer shows 1,000 for Ann and 1,000 for Ben. Each row is correct on its own terms, because each customer is connected to the account. The sum of those rows is 2,000, which is more than the money that exists.
Whether that is acceptable depends on the question:
- "How much activity touches each customer?" Counting the full amount for each customer is the right answer. The figures are not meant to add up.
- "How much of the money belongs to each customer?" The amounts must be divided, and the parts must add back to the whole.
A weight column handles the second question. Each row of the bridge records the share of the account that belongs to that customer.
Adding a weight to the bridge
The bridge table gains a third column, Weight. For each AccountID, the weights across its customers must add up to 1.
| AccountID | CustomerID | Weight |
|---|---|---|
| A1 | Ann | 0.6 |
| A1 | Ben | 0.4 |
| A2 | Ann | 0.5 |
| A2 | Ben | 0.5 |
Suppose A1 has 1,000 in transactions and A2 has 500. The weighted result is:
| Customer | Unweighted | Weighted |
|---|---|---|
| Ann | 1,500 | 850 (600 + 250) |
| Ben | 1,500 | 650 (400 + 250) |
| Sum of rows | 3,000 | 1,500 |
The weighted rows add up to the real total of 1,500. That property is the reason to use weights.
Where the weights come from
You can get weights in three ways:
- From the source system. An ownership percentage, a split ratio or a commission share is the best option. Normalize it to a fraction between 0 and 1 when you load it. A column holding 60 instead of 0.6 inflates every result a hundredfold.
- From a business rule. For example, the primary holder gets 0.7 and secondary holders share the rest.
- From an equal split. If the source has no weights and the business agrees on an even split, calculate them.
The calculated table below extends the bridge from the earlier chapter. It builds the unique pairs, then gives each pair a weight of one divided by the number of customers on that account.
AccountBridge =
VAR Pairs =
DISTINCT (
SELECTCOLUMNS (
AccountCustomer,
"AccountID", AccountCustomer[AccountID],
"CustomerID", AccountCustomer[CustomerID]
)
)
RETURN
ADDCOLUMNS (
Pairs,
"Weight",
VAR ThisAccount = [AccountID]
RETURN
DIVIDE ( 1, COUNTROWS ( FILTER ( Pairs, [AccountID] = ThisAccount ) ) )
)After creating the table, set the Weight column to Decimal number and format it as a percentage so the values are easy to read.
The allocation measure
The measure iterates the bridge rows that survive the current filters. For each row, it multiplies that row's weight by the amount of that row's account.
Total Amount = SUM ( Transactions[Amount] )Allocated Amount =
SUMX (
AccountBridge,
VAR ThisAccount = AccountBridge[AccountID]
VAR ThisWeight = AccountBridge[Weight]
RETURN
ThisWeight * CALCULATE ( [Total Amount], Accounts[AccountID] = ThisAccount )
)This is how it evaluates:
- A Customer filter from the visual reaches the bridge through the one-to-many relationship from Customers to the bridge. Only that customer's pairs remain.
- SUMX walks those bridge rows one at a time.
- For each row,
CALCULATEsets the Accounts filter to that row's account. The filter flows from Accounts to Transactions along the ordinary one-to-many relationship, so[Total Amount]returns that account's amount. - The weight scales the amount, and SUMX adds the scaled values.
The measure sets the account filter explicitly. It does not need bidirectional filtering between the bridge and Accounts, and it does not need CROSSFILTER. The only filter that must flow is the ordinary one from Customers to the bridge.
At the grand total, no customer is selected, so SUMX walks every bridge row. Each account then contributes its amount once for each customer, multiplied by weights that add up to 1. The total equals the sum of the account amounts.
Checking that the weights are valid
Weights that do not add up to 1 produce wrong numbers without any error message. The easiest check is a calculated column on Accounts that totals the weights for each account.
Weight Sum =
CALCULATE ( SUM ( AccountBridge[Weight] ) )The column is a calculated column, so context transition filters the bridge down to the current account. Then a measure counts accounts that are off:
Accounts Off Weight =
COUNTROWS (
FILTER ( Accounts, ROUND ( Accounts[Weight Sum], 6 ) <> 1 )
)The measure returns 0 for a healthy model. Two cases need attention:
- Accounts with no bridge rows.
Weight Sumis blank for these accounts, so the measure counts them. Their transactions are never allocated to any customer, so the report silently drops that money. - Rounding. Three customers with a weight of 0.3333 add up to 0.9999. Rounding to six decimals in the test avoids false alarms from floating-point noise. If you store rounded weights, the leftover is real money that goes missing. Prefer a calculated
1/3or a source value with enough precision.
The reconciliation measure from the earlier validation chapter works here too, and now it should return zero:
Allocation Check =
VAR GrandTotal = CALCULATE ( [Total Amount], ALL ( Customers ) )
VAR VisibleSum = SUMX ( VALUES ( Customers[CustomerID] ), [Allocated Amount] )
RETURN
VisibleSum - GrandTotalPut it in a table visual next to the customers and a total row. A non-zero value points to a weight problem or duplicate bridge rows.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| Allocated total is larger than the real total | Weights per account add up to more than 1, or the bridge has duplicate pairs | Check `Weight Sum`. Remove duplicates with `DISTINCT` |
| Allocated total is smaller than the real total | Weights add up to less than 1, or accounts have no bridge rows | Use `Accounts Off Weight`. Add the missing rows |
| Results are 100 times too large | Weights stored as percentages, such as 60, not as 0.6 | Divide by 100 when loading |
| Every customer shows the full amount | The visual uses `[Total Amount]` instead of `[Allocated Amount]` | Use the weighted measure in the visual |
| Allocated Amount is blank for some customers | The customer has no rows in the bridge | Add the pair, or accept blank as correct |
Limits of weighted allocation
Only additive measures can be allocated. Amounts, quantities and counts of rows can be multiplied by a weight and summed. A ratio such as margin percentage cannot, because a weighted average of percentages is not the percentage of the weighted totals. Allocate the numerator and the denominator separately, then divide:
Allocated Cost =
SUMX (
AccountBridge,
VAR ThisAccount = AccountBridge[AccountID]
RETURN
AccountBridge[Weight]
* CALCULATE ( SUM ( Transactions[Cost] ), Accounts[AccountID] = ThisAccount )
)
Allocated Margin % =
DIVIDE ( [Allocated Amount] - [Allocated Cost], [Allocated Amount] )This assumes Transactions has a Cost column. Distinct counts have no meaningful weighted form. A customer owning 0.4 of an account does not own 0.4 of a transaction ID.
Weights that change over time need extra columns. If ownership shares change, a single weight per pair is wrong for history. The bridge then needs a valid-from date and a valid-to date, and the measure must match each transaction date to the weight valid on that date. This chapter does not build that design. It is a common reason a simple weight column later has to be replaced.
Weights add cost. The measure iterates the bridge and runs a CALCULATE for each row. With a bridge of a few thousand rows this is fast. With millions of pairs, test it on real data before publishing. The next chapter returns to performance.
Exercise
Account B1 has 900 in transactions and is shared by three customers with weights 0.5, 0.25 and 0.25. What does Allocated Amount show for each customer, what should the grand total be, and what would the total be if the weights were 0.5, 0.25 and 0.5?
Show answer
The customers get 450, 225 and 225. The grand total is 900, which equals the account's amount. With weights 0.5, 0.25 and 0.5, the weights add up to 1.25, so the allocated total is 1,125 (450 + 225 + 450). That is 225 more than the real total. Accounts Off Weight would count account B1 as invalid, and Allocation Check would show 225.