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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
ariel_skn
Regular Visitor

Problem trying to sum price per month using related tables

Hi, I was playing around with some tables and I found something weird (at least to me). One of these tables is the sales table which contain all the products sold by date and quantity (important cols are product id - date) and the other is the products table which have the info about products (important cols are product id - price). (sales and products tables are related using product_id column with "many to one" cardinality and "both" cross filter direction)

 

My problem  --> If I make a visual table using Date (from sales ) and price (from products) as Values, and show only months I get wrong results. It doesn't sum the prices of every product sold in a month like I would expect. I checked it by making an additional column in the sales table named "lookup_price" following this formula:

 

 

 

 

 

lookup_price = LOOKUPVALUE(products[price],products[product_id],sales[product_id])

 

 

 

 

 

So, I'm sure the lookup_price approach is correct, but I would expect the same behaviour simply by using the raw price column. What's going on here?  (both price and lookup_price are in "sum mode"). In the attached image it's shown what I'm getting:

 

questionBI.PNG

Any help is appreciated!

 

PS: I know that strictily I should sum up the [price * quantity] for each row in sales table, but the problem I'm facing doesn't have to do anything with it, it's more like how the relationship between tables and grouping is working.

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.  Please also show the result clearly there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

Neither of them is correct.  The correct price should be the weighted average price.  You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@ariel_skn 

Measure = 
Var _A = ADDCOLUMNS(sales,"P",RELATED(products[Price]))
return
SUMX(_A,[P])

that measure works fine:

 

VahidDM_0-1641782952700.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 

Yes, that measure works fine. Thanks for that! 

But I'm not getting how powerBI is working. You say that every product_id is being counted once, so, if in a month the sales look like this:

sale     product_id 

sale1    10

sale2    10

sale3    11

with product table like this

product_id       price

10                     100

11                     110

then the sum of price column will give me 100+110 instead of 100+100+110?

 

Why is that? and make me even more confused the thing that if I use count of price instead of sum of price I get 80 in August 2019, and checking manually it happens that august 2019 has 758 sales... And I'm using "count" not "count(distinct)"...

VahidDM
Super User
Super User

Hi @ariel_skn 

 

use this measure instead:

 

Measure = 
Var _A = ADDCOLUMNS(sales,"P",RELATED(products[Price]))
return
SUMX(_A,[P])

 

When you use the Price and Date columns in your table, it will sum the Price of each Product_id onc.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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