Calculating two columsn in seperate tables with a dependency on another column

Mantrahalos

New Member
Joined
Jul 20, 2021
Messages
2
Office Version
  1. 365
Hi Mr Excel - I hope someone can help. The data below shows two tables I have in powerbi. (X and Y)

I am trying to create a column in a table (column J in the data below) - I am trying to calculate a total sales for a particular week - The cost of each item changes from week to week.
So - If in week 1 we sell 3 of widget 3 then i want to calculate 9 times the cost of widget 3 (at the week 1 price) - I have a seperate table (Table X in data below) that shows the cost of each item by each week. I cant see a way to add a relationship as neither columns have unique values.

Can anyone assist? Have I given enough information for what I am trying to achieve?

Thanks.

Mantrahalos


ABCDEFGHIJK
Table XTable Y
WeekAverage cost tableItemWeekdateStore codesales quantityItemExpect to seetotal sales this week
Week1
35​
Item3Week1
01/01/2019​
1​
3​
Item3
105​
3*item3@week1price in tableX
week2
65​
Item3week1
08/01/2019​
2​
4​
Item3
260​
week1
32​
item4week3
15/01/2019​
3​
56​
item4
1064​
week4
19​
item3week1
22/01/2019​
4​
3​
item3
week4
525​
item1Week5
29/01/2019​
4​
4​
item1
Week6
52​
item1Week6
05/02/2019​
1​
53​
item1
Week7
85​
item6week4
12/02/2019​
2​
85​
item6
Week8
96​
item1week4
19/02/2019​
3​
5​
item1
Week9
841​
Item3Week9
26/02/2019​
4​
6​
Item3
Week10
32​
Item3week9
05/03/2019​
3​
7​
Item3
Week11
23​
item4Week11
12/03/2019​
2​
89​
item4
Week12
132​
item3Week12
19/03/2019​
5​
976​
item3
Week13
32​
item1Week13
26/03/2019​
4​
5​
item1
Week14
63​
item1Week14
02/04/2019​
3​
8​
item1
Week15
32​
item6Week15
09/04/2019​
5​
3​
item6
Week16
12​
item1Week16
16/04/2019​
3​
55​
item1
Week17
3​
Item3Week17
23/04/2019​
2​
6​
Item3
Week18
113​
Item3Week18
30/04/2019​
3​
77​
Item3
Week19
21​
item4Week19
07/05/2019​
84​
item4
Week20
21​
item3Week20
14/05/2019​
46​
item3
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi Mantrahalos,

I'm unsure why you would multiply by 9 if the sales are 3 so I've assumed you meant 3.
I suspect the second row of the Y table should be for week2 to provide the result 260, so I have changed it accordingly.
Table X would benefit from a year, or actual date, to support data which may overlap a year.
You also have some entries which have no matches for the specified week number so I have shown "No price found". In those cases if you actually want the item price from an earlier week to be used then I would employ a different formula.

Mantrahalos.xlsx
ABCDEFGHIJK
1Table XTable Y
2WeekAverage cost tableItemWeekdateStore codesales quantityItemExpect to see
3Week135Item3Week101-Jan-1913Item3105
4week265Item3Week208-Jan-1924Item3260
5week132item4week315-Jan-19356item4No price found
6week419item3week122-Jan-1943item3105
7week4525item1Week529-Jan-1944item1No price found
8Week652item1Week605-Feb-19153item12756
9Week785item6week412-Feb-19285item6No price found
10Week896item1week419-Feb-1935item12625
11Week9841Item3Week926-Feb-1946Item35046
12Week1032Item3week905-Mar-1937Item35887
13Week1123item4Week1112-Mar-19289item42047
14Week12132item3Week1219-Mar-195976item3128832
15Week1332item1Week1326-Mar-1945item1160
16Week1463item1Week1402-Apr-1938item1504
17Week1532item6Week1509-Apr-1953item696
18Week1612item1Week1616-Apr-19355item1660
19Week173Item3Week1723-Apr-1926Item318
20Week18113Item3Week1830-Apr-19377Item38701
21Week1921item4Week1907-May-1984item41764
22Week2021item3Week2014-May-1946item3966
Sheet1
Cell Formulas
RangeFormula
K3:K22K3=IFERROR(INDEX($B$3:$B$9999,MATCH(1,INDEX(($A$3:$A$9999=F3)*($C$3:$C$9999=J3),0,1),0))*I3,"No price found")
 
Upvote 0
Solution
Hi Toadstool - Thank you so much for taking the time to reply - You were right - i did make some basic errors in my post - which you spotted and put right. I am sorry to say that my plans for the way this works changed after some further thought - so i didn't use this in the end - but just wanted to type a quick note of appreciation.

Mantrahalos
 
Upvote 0
Thanks for letting me know.

I started programming almost 50 years ago so I'm pretty sure 99%+ of anything I've written is now obsolete... although probably not as quickly as this ;-)
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,980
Members
452,540
Latest member
haasro02

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