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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Calculate Cost per Product SQL

Hello! 

 

If this has been asked before I am sorry but I did have a good look and I couldnt find anything on this, but I sure bet it has been asked before.

 

So I will do my best to explain the siutation, our SQL database has: 

db_contracts.[contract]

db_product.[unit_cost]

db_sales.[units]

 

I need help working out how do calculate the total cost of the contracts

filter: Contact

totalcost = db_sales.[units]*db_product.[unit_cost]

 

 

 

1 ACCEPTED SOLUTION

Hello @Anonymous 

 

and how are they connected? However you need to create a measure that looks like this

SUM(Product[Costs])*SUM(Sales[Units])

and in the visual you put the contract n. and this measure. But as I already said, all tables need to be connected first.

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

3 REPLIES 3
Jimmy801
Community Champion
Community Champion

Hello @Anonymous 

 

use SUMX for this. Here a code that should work out for you

SUMX(YOURTABLE, db_sales.[units]*db_product.[unit_cost])

Are these fields both in the same table I suppose. What you mean with filter? In case apply a Filter to your table like FILTER(YOURTABLE, [Contract]="abc")


If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Anonymous
Not applicable

Hi Jimmy, 

 

Thanks for the quick reply. 

 

Sadly they are not in the same table, each of the fields above are all in their own tables.

We have a table of contracts this is what we want to filter on (i.e we want to see the cost of X contract) , a table of products that contains how much each product costs (unit_cost) and a table of sales that contains the number of units sold (units)

 

Capture.PNG

 

Thanks

Hello @Anonymous 

 

and how are they connected? However you need to create a measure that looks like this

SUM(Product[Costs])*SUM(Sales[Units])

and in the visual you put the contract n. and this measure. But as I already said, all tables need to be connected first.

 

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.