Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hello,
I have products that are sold both by themselves and occasionally parts of kits that are listed as a single line item on our invoices.
The invoices are set up like this:
Product | Quantity | Unit Price | Total |
A | 2 | $7.50 | $15.00 |
B | 7 | $4.25 | $29.75 |
C | 19 | $16.13 | $306.47 |
The Product table is set up like this:
Product | Components | Quantity |
A | A | 1 |
B | B | 1 |
C | A | 1 |
C | B | 2 |
How can I write a measure that will show me the total number of A and B sold?
Solved! Go to Solution.
Hi @iepps ,
For your logic, you could create the calculated columns and measures below.
Column = LOOKUPVALUE('Table'[Unit Price],'Table'[Product],'table 2'[Components]) Column 2 = VAR a = LOOKUPVALUE ( 'Table'[Quantity], 'Table'[Product], 'table 2'[Product] ) RETURN 'table 2'[Quantity] * a Measure = CALCULATE(SUM('table 2'[Column 2]))*CALCULATE(MAX('table 2'[Column]))
Here is the output.
Hope this can make sense.
Best Regards,
Cherry
Hi @iepps ,
Do you want to get the output below?
If so, you could create the calculated column in table 2 like below.
Column = LOOKUPVALUE('Table'[Unit Price],'Table'[Product],'table 2'[Components])
Then create the measure.
Measure = ( CALCULATE ( SUM ( 'table 2'[Column] ) ) * CALCULATE ( SUM ( 'table 2'[Quantity] ) ) + CALCULATE ( SUM ( 'Table'[Total] ) ) )
You also could refer to my attachment.
Best Regards,
Cherry
Sorry, I think I might not have been clear. The first table in the post is simulating an invoice and the second is a fact table showing the products and their components. The amount in the second table is just the unit price we have set for the product. The ideal result would be to show the total of A by itself combine with the quantity of A from the product:
A * Quantity + (The amount of A in C)*Quantity
The correct result for A would be a quantity of 21 for a total sale of $157.50 and B would be a quantity of 45 for a total of $191.25.
Hi @iepps ,
For your logic, you could create the calculated columns and measures below.
Column = LOOKUPVALUE('Table'[Unit Price],'Table'[Product],'table 2'[Components]) Column 2 = VAR a = LOOKUPVALUE ( 'Table'[Quantity], 'Table'[Product], 'table 2'[Product] ) RETURN 'table 2'[Quantity] * a Measure = CALCULATE(SUM('table 2'[Column 2]))*CALCULATE(MAX('table 2'[Column]))
Here is the output.
Hope this can make sense.
Best Regards,
Cherry
Hello! It has since a lot of time since you made this reply, I found it useful.
However, I can't achieve the same result when I want to filter by other columns on the Sales Table (status, distribuitor,seller ).I can succesfully create a column with all the sales per Kit but it doesn't work with filters.
How can I make this dynamic to context filters?
Thanks and regards!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
71 | |
68 | |
50 | |
30 |
User | Count |
---|---|
119 | |
101 | |
73 | |
65 | |
40 |