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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Fistachpl
Helper II
Helper II

How to count sales of assemblies

Hello,

 

My company sells products. Some products are sold separately but very often are sold in a group (assembly). E.g.:

15 Regular cookies (1 product)
15a Raisins (1 product)
Assembly1 Cookies with raisins (Total of 2 products: 1x regular cookies, 1x Raisins)

In a sales report I have:
Date of sale, Product or assembly sold

Date of saleProduct IDAmount sold
15.01.20241512
16.01.202415a4
16.01.2024Assembly12
03.02.2024155


I have a table with products and another table of assemblies where I have information which assembly has which products in it.

 

So In total I sold in January of 2024:
 

Product or assembly IDAmount
1517 (15x separate, 2 as part of Assembly1)
15a6 (4x separate, 2 as part of Assembly1)

 

How do I calculate it? I do not need a DAX formula of course but at least what I should look for.

 

Thank You!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Fistachpl ,

 

First of all thanks to ryan_mayu  for the quick reply. Please allow me to add some thoughts:

We can create measures.

_soldDirectly = 
    CALCULATE(
        SUM(TSalesData[Amount sold]),
        TSalesData[Item Sold] IN VALUES(TProducts[Product ID])
    )
_salesThroughAssemblies = 
var _sold=CALCULATE(SUM('TSalesData'[Amount sold]),FILTER(ALLSELECTED('TSalesData'),[Product name] in VALUES('TSalesData'[Product name])))
var _cost=CALCULATE(SUM('TProducts'[Production Cost]),FILTER(ALLSELECTED('TProducts'),[Product Name] in VALUES('TSalesData'[Product name])))
RETURN _sold*_cost
Total = [_soldDirectly]+[_salesThroughAssemblies]

Then the result is as follows.

vtangjiemsft_0-1725344844281.png

If I have misunderstood your needs please clarify in a follow up reply.

 

Best Regards,

Neeko Tang

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

10 REPLIES 10
Anonymous
Not applicable

Hi @Fistachpl ,

 

First of all thanks to ryan_mayu  for the quick reply. Please allow me to add some thoughts:

We can create measures.

_soldDirectly = 
    CALCULATE(
        SUM(TSalesData[Amount sold]),
        TSalesData[Item Sold] IN VALUES(TProducts[Product ID])
    )
_salesThroughAssemblies = 
var _sold=CALCULATE(SUM('TSalesData'[Amount sold]),FILTER(ALLSELECTED('TSalesData'),[Product name] in VALUES('TSalesData'[Product name])))
var _cost=CALCULATE(SUM('TProducts'[Production Cost]),FILTER(ALLSELECTED('TProducts'),[Product Name] in VALUES('TSalesData'[Product name])))
RETURN _sold*_cost
Total = [_soldDirectly]+[_salesThroughAssemblies]

Then the result is as follows.

vtangjiemsft_0-1725344844281.png

If I have misunderstood your needs please clarify in a follow up reply.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

ryan_mayu
Super User
Super User

why product 15's amount is 17?  12 for Jan, 5 for Feb and 2 for assemebly1. should that be 19?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I wrote that in January 🙂

the amount for 15 in Jan is 12. Then should that be 12+2=14?

 

maybe you can create a new column

 

Column = if('Table'[Product ID]="Assembly1",'Table'[Amount sold],'Table'[Amount sold]+maxx(FILTER('Table',year('Table'[Date of sale])=year(EARLIER('Table'[Date of sale]))&&month('Table'[Date of sale])=month(EARLIER('Table'[Date of sale]))&&'Table'[Product ID]="Assembly1"),'Table'[Amount sold]))
 
12.PNG




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Ok but the code works only for Assembly1. But this I can work around. Can You explain the code ? Thank You

then could you pls update the sample data to be closer to your real data? 

Currently the wrokaround for you is to update the assembly 1 to the one in your real data





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Sure thing. I attach an excel file with product configurations:

 

Sales of assemblies data.xlsx

there are 5 sheets in the excel. Could you pls let me know the expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




The endresult is to calculate and present in a table information how many times each product was sold. The product can be sold as standalone item but also as part of the assembly. Basically what You did before but Your code would work only for Assembly 1 and there are much more assemblies.

I need to have a measure, that for Each product calculates:

Amount of product sold as standalone 
+
Goes through each assembly and if the product is part of this assembly then should calculate the amount of times the assembly was sold and multiply it by amount of this product that is in the assembly.


Sales of assemblies data.pbix

I think this is how it should work:

There should be two measures:

_directSales - which calculates the amount of sold products as standalone producst - that is straightforward

_salesThroughAssemblies which should work like this:

 

It should iterate through the TProducts 
For each product it should iterate through TAssembliesParts (which should be filtered to the assemblies that consist of the selected product. 
Then it should iterate through this filtered table and for each assembly find a name, then find in TSalesData how many times the assembly was sold and then multiply it by the Product amount of the selected product in the selected assembly. 
Then it should sum it all up. 

What then would be left is to add _directSales + _salesThroughAssemblies

Yes You are right. I looked at product number. Sorry about that. But the problem is dtill the same 🙂 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors