Array formula to determine changes in price and time of changes

L

Legacy 332279

Guest
Hey!

I've been looking around for a while in the forums, but haven't been able to find a solution. I'm working on an array formula that is supposed to determine when a price of an item has changed and what the new price is based on an inventory log that contains several different items. I've got the core functionality down, but I now struggle with two things:

1) I would like to omit all false values from the result, so that the resulting list doesn't contain any blank cells. I've tried using the solution provided by Aladin in this post, but I can't wrap my head around how to incorporate my array formula into that solution.

2) I would also like for the formula to include the first first registered price of an item, which the current formula omits, but again I'm unsure as to how.

This is the current array formula:
Code:
{=IF((INDEX(I:I,SMALL(IF(COUNTIF(Q3,A1:A10),ROW(A1:A10)-MIN(ROW(A1:A10))+1),ROW(INDIRECT("1:30"))))<>INDEX(I:I,SMALL(IF(COUNTIF(Q3,A1:A10),ROW(A1:A10)-MIN(ROW(A1:A10))+1),ROW(INDIRECT("2:30"))))),(INDEX(G:I,SMALL(IF(COUNTIF(Q3,A1:A10),ROW(A1:A10)-MIN(ROW(A1:A10))+2),ROW(INDIRECT("1:30"))),{1,3})))}

In essence the parent IF function checks if a row that contains data on an item (determined by an ID-number in Q3) has a different price than the previous row of data on the same item. If this is true, then it returns the time of the change (from column G) and the new price (from column I). If false, it simply returns false.

The following is the test sheet I've been using to create what I have so far (without irrelevant information):

ABCDEFGHI
1IDNQPSMTQV
2101...............01-01-15...50
3102...............01-01-15...90
4101...............02-01-15...50
5103...............02-01-15...200
6102...............02-01-15...90
7101...............02-01-15...50
8101...............15-01-15...60
9101...............15-01-15...60
10102...............15-01-15...80

<tbody>
</tbody>


Then, say if Q3 is set to 101, the following is a comparison of the current result and the desired result:

Current result Desired result

<tbody>
</tbody>
FALSEFALSE01-01-1550
FALSEFALSE15-01-1560
15-01-1560
FALSEFALSE
#NUM!#NUM!
#NUM!#NUM!
#NUM!#NUM!
#NUM!#NUM!
#NUM!#NUM!
#NUM!#NUM!

<tbody>
</tbody>


Any help would be greatly appreciated!
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Ok, so I figured out how to include the first registered line of data by changing the countif-function to accept both the ID number and the text string "ID".

I'm still no closer to a solution on my first issue though.
 
Upvote 0
Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
1​
IDNQPSMTQVID
101​
2​
101
1/1/2015
50
dateprice
3​
102
1/1/2015
90
1/1/2015
50​
4​
101
1/2/2015
50
1/15/2015
60​
5​
103
1/2/2015
200
6​
102
1/2/2015
90
7​
101
1/2/2015
50
8​
101
1/15/2015
60
9​
101
1/15/2015
60
10​
102
1/15/2015
80

A2:A10 is named id, G2:G10 date, and I2:I10 price.

Moreover, Ivec is defined using Formulas | Name Manager as referring to:
Rich (BB code):

=ROW(price)-ROW(INDEX(price,1,1))+1

L1: 101 (An ID of interest.)

K3, control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IFERROR(INDEX(date,SMALL(IF(FREQUENCY(IF(price<>"",
    IF(id=$L$1,MATCH(price,price,0))),Ivec),Ivec),ROWS(K$2:K2))),"")

L3, just enter and copy down:
Rich (BB code):

=IF(K3="","",INDEX(price,MATCH($K3,date,0)))

Question. Do we need to list 18-Jan-2015 if the price falls back to 50?
 
Last edited:
Upvote 0
Thank you Aladin! A much more elegant formula than mine.

Yes, unfortunately prices can go both ways, so the formula would have to pick up that as well. Do you see any good solutions for incorporating that?
 
Upvote 0
Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
1​
IDNQPSMTQVID
101​
2​
101
1/1/2015
50
dateprice
3​
102
1/1/2015
90
1/1/2015
50​
4​
101
1/2/2015
50
1/15/2015
60​
5​
103
1/2/2015
200
6​
102
1/2/2015
90
7​
101
1/2/2015
50
8​
101
1/15/2015
60
9​
101
1/15/2015
60
10​
102
1/15/2015
80

<tbody>
</tbody>


A2:A10 is named id, G2:G10 date, and I2:I10 price.

Moreover, Ivec is defined using Formulas | Name Manager as referring to:
Rich (BB code):

=ROW(price)-ROW(INDEX(price,1,1))+1

L1: 101 (An ID of interest.)

K3, control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IFERROR(INDEX(date,SMALL(IF(FREQUENCY(IF(price<>"",
    IF(id=$L$1,MATCH(price,price,0))),Ivec),Ivec),ROWS(K$2:K2))),"")

L3, just enter and copy down:
Rich (BB code):

=IF(K3="","",INDEX(price,MATCH($K3,date,0)))

Question. Do we need to list 18-Jan-2015 if the price falls back to 50?

I've discovered a major problem with the formula. If you you change the value 60 in I8 (in the test sheet above) to 90, the formula will result in showing the price change as happening at 1/1/2015 instead of 1/15/2015 as it should. That is to say, the formula retrieves the date from the third row, which contains data from ID 102, instead of the eighth.
 
Upvote 0
I've discovered a major problem with the formula. If you you change the value 60 in I8 (in the test sheet above) to 90, the formula will result in showing the price change as happening at 1/1/2015 instead of 1/15/2015 as it should. That is to say, the formula retrieves the date from the third row, which contains data from ID 102, instead of the eighth.

You are right about that. Plus we got a more funtamental problem: The same price appearing for the same id on a later date. See whether the following set up satisfies...

Row\Col
A​
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
L​
1​
IDNQPSMTQVEvalID
101​
2​
101
1/1/2015
50
50​
count
4​
3​
102
1/1/2015
90
90​
dateprice
4​
101
1/2/2015
50
#
1/1/2015
50​
5​
103
1/2/2015
200
200​
1/15/2015
90​
6​
102
1/2/2015
90
#
1/15/2015
60​
7​
101
1/2/2015
50
#
1/30/2015
50​
8​
101
1/15/2015
90
90​
9​
101
1/15/2015
60
60​
10​
102
1/15/2015
80
80​
11​
101
1/30/2015
50
50​

J2, control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IF(ISNA(MATCH(I2,$J$1:J1,0)),I2,
   IF(ISNA(MATCH(I2,$J$1:J1,0))*ISNA(MATCH($A2&"|"&$G2,$A$1:A1&"|"&$G$1:G1,0)),I2,
   IF(ISNUMBER(LOOKUP(9.99999999999999E+307,1/($A$1:A1=A2),$I$1:I1)),
   IF(LOOKUP(9.99999999999999E+307,1/($A$1:A1=A2),$I$1:I1)<>I2,I2,"#"),"#")))

L2, control+shift+enter, not just enter:
Rich (BB code):

=SUM(IF(A2:A11=L1,IF(ISNUMBER(J2:J11),1)))

K4, control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IF(ROWS($K$2:K2)<=$L$2,INDEX($G$2:$G$11,SMALL(IF($A$2:A11=$L$1,
   IF(ISNUMBER($J$2:$J$11),ROW($G$2:$G$11)-ROW($G$2)+1)),ROWS($K$2:K2))),"")

L4, control+shift+enter, not just enter, and copy down:
Rich (BB code):

=IF($K4="","",INDEX($J$2:$J$11,SMALL(IF($A$2:$A$11=$L$1,
   IF($G$2:$G$11=$K4,ROW($J$2:$J$11)-ROW($J$2)+1)),
   COUNTIFS($K$4:K4,K4))))
 
Upvote 0
This seems to work perfectly, thank you! I would certainly have given up if not for this.
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,739
Members
449,116
Latest member
alexlomt

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