Calculate The Difference Between two Fields in Two Related Fields

Hashiru

Active Member
Joined
May 29, 2011
Messages
286
Table 1
RIDAmountCount
Elephant5002
Lion6004
Zebra8006

<tbody>
</tbody>










Table 2
RIDAmountCount
Deer5002
Lion8005
Zebra7005

<tbody>
</tbody>









Desired Result
RIDAmountCount
Elephant-500-2
Deer+500+2
Lion+200+1
Zebra-100-2

<tbody>
</tbody>









RID is the related field

What formula do I use in power query or Power Pivot?

Thanks.

Note Question should be:
icon1.png
Calculate The Difference Between two Fields in Two Related Tables
 
Last edited:

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Why Zebra Count is -2 ?

RIDAmtCnt
Deer
500​
2​
Elephant
-500​
-2​
Lion
200​
1​
Zebra
-100​
-1​
 
Upvote 0
so you can try:
after load tables into PQ:
table1
multiply Amount and Count by -1
then do this:
Code:
[SIZE=1]let
    Source = Table.Combine({Table1, Table2}),
    #"Grouped Rows" = Table.Group(Source, {"RID"}, {{"Amount", each List.Sum([Amount]), type number}, {"Count", each List.Sum([Count]), type number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"RID", Order.Ascending}})
in
    #"Sorted Rows"[/SIZE]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,014
Messages
6,128,282
Members
449,436
Latest member
blaineSpartan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top