Forum Discussion
Calculate Value with a measured quantity based on different types
Create a Size/Option Table (Table2): You've already provided this table. Ensure it is in your data model.
Create a measure for Shortage: Instead of having three separate measures, you can create one measure for Shortage.
SHORTAGE =
CALCULATE(
SUM(Table1[Item Quantity]),
Table1[Type] = "CONTAINER"
) - CALCULATE(
SUM(Table1[Item Quantity]),
Table1[Type] = "FOOD"
)
Create measures for Options E, A, and P:
OPTION_E = [SHORTAGE] * RELATED(Table2[Option E])
OPTION_A = [SHORTAGE] * RELATED(Table2[Option A])
OPTION_P = [SHORTAGE] * RELATED(Table2[Option P])
Build the visual table/matrix: Use a table or matrix visual in Power BI or your preferred tool. Place the following fields in the appropriate areas:
- Rows: Customer Name, Product Size
- Values: Shortage, OPTION E, OPTION A, OPTION P
This will give you the desired result table with Shortage and options calculated based on the size and values from Table2.
Here's a summary of the measures:
SHORTAGE =
CALCULATE(
SUM(Table1[Item Quantity]),
Table1[Type] = "CONTAINER"
) - CALCULATE(
SUM(Table1[Item Quantity]),
Table1[Type] = "FOOD"
)
OPTION_E = [SHORTAGE] * RELATED(Table2[Option E])
OPTION_A = [SHORTAGE] * RELATED(Table2[Option A])
OPTION_P = [SHORTAGE] * RELATED(Table2[Option P])
Make sure that the relationships between the tables are set up correctly, and the calculations should work as expected.
Thank you, this is exactly what I was trying to do. I simplified the shortage measure and created three measures to be used in the visuals, however, I am getting an error on the "option" measurements.
Here is what I did:
1. I created a table (below) using the "Enter Data" function
2. I created a relationship to the sales data table to this table in a Many:1 relationship via the "FAMILY" field.
3. Created the option Measures in the sales table (Table 1)
Error: "The column 'tblSWPricing[OPTION_E]' either doesn't exist or doesn't have a relationship to any table available in the current context."
| FAMILY | OPTION_E | OPTION_A | OPTION_P |
| SIZE A | 10.26 | 18.46 | 21.96 |
| SIZE B | 10.87 | 21.75 | 31.03 |
| SIZE C | 12.08 | 29 | 41.35 |
| SIZE D | 10.87 | 21.75 | 31.03 |
| SIZE E | 12.08 | 29 | 41.35 |
| SIZE F | 2.26 | 3.4 | 4.88 |
| SIZE G | 6.8 | 8.44 | 11.59 |
| SIZE H | 11.28 | 18.46 | 21.96 |
- awarriorpoet2 years ago
Helper I
I created a measure that seems to be working. I could not get RELATE() to work.
OPTION_P_$ = Table1[Shortage] *LASTNONBLANK(SELECTCOLUMNS(RELATEDTABLE(tblSWPricing),"OPTION_P",tblSWPricing[OPTION_P]),1)