Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
iepps
Frequent Visitor

Combining Sales Quantities for Products in Kits

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:

ProductQuantityUnit PriceTotal
A2$7.50$15.00
B7$4.25$29.75
C19$16.13$306.47

 

The Product table is set up like this:

ProductComponentsQuantity
AA1
BB1
CA1
CB2

 

How can I write a measure that will show me the total number of A and B sold?

1 ACCEPTED 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.

Capture.PNG

Hope this can make sense.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @iepps ,

Do you want to get the output below?

Capture.PNG

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

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Capture.PNG

Hope this can make sense.

Best Regards,

Cherry

 

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

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!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.