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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Charmaine
Frequent Visitor

Sumif between two tables

Hello all, do you have any ideas how to merge two table with sumif condition?  

 

I have two tables as shown below and I would like to have a new column in TABLE 2 which in excel the new column would be  sumif(TABLE1[Medium Batch Name], TABLE2[Medium Batch Name], TABLE1[record_1])

 

TABLE 1

TABLE 1

TABLE 2

TABLE 2TABLE 2

1 ACCEPTED SOLUTION
nickchobotar
Skilled Sharer
Skilled Sharer

@Charmaine

 

Here is one of the approaches to solve this given that you do not have a relationship between the two tables.

 

=CALCULATE(
SUM(Table1[Record 1]),
FILTER(
	Table1, 
	Table1[Col One] = CALCULATE(VALUES(Table2[Col One]))
	)
)

image.png

 

 

If these tables are related in your model your calc column DAX will be simply  = CALCULATE(SUM(Table1[Record 1]))

 

Thanks, Nick -

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi @Charmaine,

 

Try this calculated column formula in Table2

 

=CALCULATE(SUM(Table1[Number]),FILTER(Table1,Table1[Text]=EARLIER(Table2[Text])))

 

Hope this helps.


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

@Charmaine

 

Here is one of the approaches to solve this given that you do not have a relationship between the two tables.

 

=CALCULATE(
SUM(Table1[Record 1]),
FILTER(
	Table1, 
	Table1[Col One] = CALCULATE(VALUES(Table2[Col One]))
	)
)

image.png

 

 

If these tables are related in your model your calc column DAX will be simply  = CALCULATE(SUM(Table1[Record 1]))

 

Thanks, Nick -

Anonymous
Not applicable

Is there something that would cause = CALCULATE(SUM(Table1[Record 1])) to not function properly?

 

I have a smiliar situation where I have two tables.  One table lists shipment numbers (Table 1 [Shipment Number]) and quantities of product on the shipment (Table 1[Qty]).  The shipment numbers in this table are not unique, as there is a separate line item for each item for each item shipped in the shipment as below.  What I would like to do is populate Table 2[Total Qty].  Shipment Numbers are related in a one to many relationship between the two tables.  I entered the formula =CALCULATE(SUM(Table 1[Qty])) and every cell shows up as a blank.  If I remove the CALCULATE function and only use sum, it sums all of the values, but appears to be unable to break them down by shipment.  For example, if 34,000,000 units were shipped in all shipments, that's the number I get in all cells.

 

Both shipment numbers are text and the Qty column is whole number (and I tried decimal number as well) and that doesn't appear to have solved it.  Any thoughts on something I might be overlooking that's preventing this from calculating?

 

Edit: I should note that I entered the above formula as a new column while in Table 2 and not within edit query.

 

Thanks

 

Table 1

Shipment NumberProductQty
7437402A1300
7437402B700
7437402D650
7438014C800
7438014D400
7438093A1900
7438842D750
7438842C900

Table 2

Shipment NumberTotal Qty
7437402 
7438014 
7438093 
7438842 

Hi,

It looks like you are writing a calculated column rather than a measure.  Create a relationship from the Shipment Number column of Table1 to the Shipment Number column of Table2 (you do not need to have the Qty column in Table2).  To your visual, drag the Shipment Number column from Table2 and write this measure

=SUM(Table 1[Qty])

Hope this helps.


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

Thank you so much, Nick. Smiley WinkSmiley Wink

Thank you @Charmaine

 

Hopefully, it was helpful.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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