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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
paulomartins
Frequent Visitor

Measure to sum a column based on other tables column

Hello guys, it's my first post here and I'm very glad to be part of this forum.

 

Recently I'm trying to deal with a logical sum in DAX and to be honest I not dealing with it really well...

 

My problem is:

 

I have 3 tables:

 

paulomartins_0-1657066142563.png

 

paulomartins_1-1657066191404.png

 

paulomartins_2-1657066220496.png

 

I want to sum the MB52[Quantity] based on Current and Old Keys, reaching this result:

 

paulomartins_3-1657066242560.png

 

Identifying [Current Key] and suming the quantity of the [Old. Key] with owns [Current Key] quantity.

 

I tried this code but with no sucess 😞

 

[Sum. Quantity] =
IF
(

'KEYS'[Old. Key] <> "";

CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Old. Key])) + CALCULATE(SUM(MB52[Quantity]) ; MAX(MB52[Key]) = MAX('KEYS'[Current Key]));

SUM(MB52[Quantity])

)

 

I apreciate a lot your help and thanks anyway 🙂

1 ACCEPTED SOLUTION
vapid128
Solution Specialist
Solution Specialist

in MB52 table

add colnum

current key

var _newKey=lookupvalue(keys[current key],keys[old key],MB52[KEY])

return

if(_newKey = blank(), MB52[KEY],_newKey)

 

then make relationhip MB52[current key] and product[current key]

View solution in original post

2 REPLIES 2
paulomartins
Frequent Visitor

It's not the expected way I was thinking to reach it, but it worked like a charm hahahaha

 

Thanks so much! 

vapid128
Solution Specialist
Solution Specialist

in MB52 table

add colnum

current key

var _newKey=lookupvalue(keys[current key],keys[old key],MB52[KEY])

return

if(_newKey = blank(), MB52[KEY],_newKey)

 

then make relationhip MB52[current key] and product[current key]

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.