Modifying LET formula to include an additional data check

shstrating

Board Regular
Joined
Sep 8, 2009
Messages
65
Office Version
  1. 365
Platform
  1. Windows
I was graciously provided a LET formula by member felixstraube that I would now like to modify to include an additional check of the data and only return values that match this extra condition.

Here is the original LET formula: =LET(rd,$A$1:$A$131788, r_hasCCP,FILTER(ROW(rd),ISNUMBER(FIND("IM=LAM124",rd))), r_hasPO,FILTER(ROW(rd),ISNUMBER(FIND("PO=",rd))), textIndex,BYROW(r_hasCCP,LAMBDA(x,MAX(FILTER(r_hasPO,r_hasPO<x)))), TEXTAFTER(CHOOSEROWS(rd,textIndex),"PO=") )

I admit I do not fully understand how the textIndex BYROW calculation works or how the CHOOSEROWS in the final calculation works, but the formula got me the results I needed.
It queries my column of data to find every instance of "IM=LAM124" and then it looks backwards from IM=LAM124 and returns the value of the corresponding PO= field minus the "PO=" prefix.
I have the same single column of data that I now want to query for a slightly different condition with a slightly modified output.

So now I would like to modify this formula to do the following:
- Perform the same calculation as the original "r_hasCCP" function (to be renamed "r_hasUND") but looking for the string "ON=(UND)" instead of "IM=LAM124". (I know how to do this)
- When "ON=(UND)" is found then check the 9th row following that record and determine whether the string begins with "PO". (I don't know how to do the "...check the 9th row following..." bit)
- If "PO" is found, look backwards and return the value of the "PO=" entry that comes before the "ON=(UND)" that was found previously. (Maybe the existing TEXTAFTER calc in the original formula would still work?)
- If "PO" is not found, do nothing.
- Continue down the column of data performing the same steps.

By way of explaining the data a bit, all records that begin with "PO=" are what we call PO Tables.
Each PO= record is the beginning of a new PO table.
What I am trying to accomplish is to get a list of every PO Table that contains only one "ON=" record where that one "ON=" record must equal "ON=(UND)".
There may be PO Tables that contain only one "ON=" record that is not equal to "(UND)" and these are to be ignored.

In the following set of example data when the modified LET function (or other solution) is working properly it should return the result shown in C1 because the 9th row after the ON=(UND) in ColB Row28 begins with "PO".
DPGP-HVGRD-124 would be an incorrect result because the 9th row after the ON=(UND) in ColB Row5 begins with "ON".

Thanks in advance for any assistance offered.

kbe3-NEW.xlsx
BC
1PO=DPGP-HVGRD-124DPGP-HVGRD-125
2OG=Grain Direction
3POLA=AFUFU-3D-GS-SD1
4POLA=AFUFU-3D-GS-SD2
5ON=(UND)
6IM=UNDCOL
7OD=*** Undecided Color ***
8O1=0
9O2=0
10O3=0
11O4=0
12O5=0
13O6=0
14ON=H
15IM=LAM124
16OD=OPT: Horizontal Grain Direction
17O1=0
18O2=0
19O3=0
20O4=0
21O5=0
22O6=0
23SO=DPGP-LAM-EDGE
24PO=DPGP-HVGRD-125
25OG=Grain Direction
26POLA=AFUFU-3D-GS-SD1
27POLA=AFUFU-3D-GS-SD2
28ON=(UND)
29IM=UNDCOL
30OD=*** Undecided Color ***
31O1=0
32O2=0
33O3=0
34O4=0
35O5=0
36O6=0
37PO=DPGP-HVGRD-126
kbe
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Try:
Excel Formula:
=LET(d,B1:B37,r,IF(LEFT(d,8)="ON=(UND)",ROW(d)),TOCOL(TEXTAFTER(IF(LEFT(INDEX(d,r+9),3)="PO=",INDEX(d,r-4)),"PO="),2))
 
Upvote 0
Minor change to make this more robust if data isn't always starting from row 1.
Excel Formula:
=LET(d,B1:B37,r,IF(LEFT(d,8)="ON=(UND)",SEQUENCE(ROWS(d))),TOCOL(TEXTAFTER(IF(LEFT(INDEX(d,r+9),3)="PO=",INDEX(d,r-4)),"PO="),2))
 
Upvote 0
@Cubist: Thank you for that formula!
It works a treat! (y)
Now I just need to spend some time trying to 'reverse engineer' your hard work to try to understand how it works. :)
 
Upvote 0
Well, I spoke too soon.
That LET formula is not working when run against something other than my sample data.
I haven't sorted out how the formula is working yet in order to troubleshoot, but I suspect the issue is because of one thing I neglected to mention in my original post.
The PO= record will not always be 4 rows above the 'orphaned' ON=(UND) record and I am guessing that this is tripping up the formula.
The PO= record will never be less than 2 rows above the ON=(UND) record, but it could be any number of rows greater than 2 rows above the ON=(UND) record.
Here are three examples showing how much that row count can change within a single file.
ks2.3
AB
1PO=BS2C22-BLL-LAM-FRNT_BS2C2230BLL
2OG=Laminate Front Finish
3POLA=AFUFU-3D-SC-DF-H
4POLA=AFUFU-3D-SC-DF-V
5POLR=90
6POLA=AFUFU-3D-SP-DF-H
7POLA=AFUFU-3D-SP-DF-V11 rows
8POLR=90
9POLA=AFUFU-3D-SC-TP-H
10POLA=AFUFU-3D-SC-TP-V
11POLR=90
12ON=(UND)
13IM=UNDCOL
14OD=*** Undecided Color ***
15O1=0
16O2=0
17O3=0
18O4=0
19O5=0
20O6=0
21PO=BS2C22-BLL-LAM-TOP_BS2C2230BLL
22OG=Laminate Top Finish
23POLA=AFUFU-3D-WS3 rows
24ON=(UND)
25IM=UNDCOL
26OD=*** Undecided Color ***
27O1=0
28O2=0
29O3=0
30O4=0
31O5=0
32O6=0
33PO=CORE-PNT_BS2DW18O
34OG=Paint Finish
35POLA=AFUFU-3D-SV-DF-H
36POLA=AFUFU-3D-SV-DF-V
37POLR=90
38POLA=AFUFU-3D-SV-SU
39POLA=AFUFU-3D-SV-DF
40POLA=AFUFU-3D-SC-TP-H
41POLA=AFUFU-3D-SC-TP-V
42POLR=90
43POLA=AFUFU-3D-SC-DF-H
44POLA=AFUFU-3D-SC-DF-V22 rows
45POLR=90
46POLA=AFUFU-3D-SC
47POLA=AFUFU-3D-SC-DF
48POLA=AFUFU-3D-SP
49POLA=AFUFU-3D-SP-DF
50POLA=AFUFU-3D-SP-DF-H
51POLA=AFUFU-3D-SP-DF-V
52POLR=90
53POLA=AFUFU-3D-SV
54POLA=AFUFU-3D-SV-BK
55ON=(UND)
56IM=UNDCOL
57OD=*** Undecided Color ***
58O1=0
59O2=0
60O3=0
61O4=0
62O5=0
63O6=0
Sheet1
 
Upvote 0
Ok, How about this?
Excel Formula:
=LET(d,A1:A100,c,"PO=",r,IF(LEFT(d,8)="ON=(UND)",SEQUENCE(ROWS(d))),
TEXTAFTER(FILTER(SCAN(0,d,LAMBDA(a,b,IF(LEFT(b,3)=c,b,a))),IF(ISNUMBER(r),LEFT(INDEX(d,r+9),3)=c)),c))
 
Upvote 0
Solution

Forum statistics

Threads
1,224,813
Messages
6,181,106
Members
453,021
Latest member
Justyna P

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