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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
lucasrm
Frequent Visitor

Sum a colum if the key is present on another table DAX

Hello everyone,


I have an item table:

item_id   price

01           5

02          10

03            7


And I have an event table:

event_id     item_id

grty           02

bfgz          03

fdbx          03

azrq          02


One item can be affected by multiple events.


I would like to have a measure that will sum the total price of all items that are present in the event table.

In this example, that would be item 02 and 03. Therefore the total price would be 17.


Can anyone kindly help me with this DAX problem?


Thanks in advance,

Lucas

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@lucasrm , Try one of the two. if first one joined

 

calculate(sum(Table[price]), filter(event, not(isblank(event[item_id]))))

 

or

 

calculate(sum(Table[price]), filter(Table, Table[item_id] in allselected(event[item_id])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

4 REPLIES 4
negi007
Community Champion
Community Champion

@lucasrm in this case first you need to create a relationship between two tables like below

 

negi007_0-1614784051996.png

 

negi007_1-1614784071407.png

then below is output you are looking for

negi007_2-1614784098167.png

 

let me know if it helps you. attached pbix file for reference.




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



Proud to be a Super User!


Follow me on linkedin

Hello @negi007 !

Thanks for the help but unfortunately that was not what I was looking for. I had already the two tables linked. I actually needed a measure so I could calculate totals and etc.

 

I took your pbix file and used the DAX from @amitchandak and it worked!

Here's the result I was looking for:

lucasrm_0-1614789427569.png

Thanks anyway for the help!

 

amitchandak
Super User
Super User

@lucasrm , Try one of the two. if first one joined

 

calculate(sum(Table[price]), filter(event, not(isblank(event[item_id]))))

 

or

 

calculate(sum(Table[price]), filter(Table, Table[item_id] in allselected(event[item_id])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Thanks @amitchandak , it worked great!

I tried something similar before but I was afraid that this type of DAX would sum repeatedly the price for each occurence of item in the event table. I was wrong, it worked perfectly!

lucasrm_0-1614789810213.png

Thanks for your help!

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.