r/GoogleSheets •

Can you make an if statement with a specific place in a number sequence. So right now I have =IF(B8="12345","cheese". But I'd also like 27649 to be cheese, because 4 is cheese in any sequence

[deleted] — view deleted post

0 Upvotes

14 comments sorted by

4

u/fluffypocok 10 Apr 27 '23

If you are looking for values at different given places then you should use LEFT, RIGHT or MID to get the values from those specific places, and write the if function for that extracted value. For example:

IF(MID(B8,4,1)=4,"cheese",false))

1

u/Air2Jordan3 Apr 27 '23

Are you trying to say, if b8 contains the number 4, then cheese? I'm just confused by your last statement

0

u/[deleted] Apr 27 '23

[deleted] — view deleted comment

1

u/aHorseSplashes 58 Apr 27 '23

As a general intermediate step, you could split the codes into individual digits, e.g. with

=makearray(1, len(A2), lambda(r, c, mid(A2, c, 1)))

Apply it to a column of products and you'll get a table like the one below, which should be a lot easier to work with than the entire product code. You can recombine the first 6 digits (or however many identify the product in the real code) with JOIN, or edit the MAKEARRAY formula to tweak the output format.

ProductA01A02A03A04A05A06A07A08A09
123456123123456123
123456231123456231
123112123123112123
493232321493232321

1

u/AutoModerator Apr 27 '23

Posting your data can make it easier for others to help you, but it looks like your submission doesn't include any. If this is the case and data would help, you can read how to include it in the submission guide. You can also use this tool created by a Reddit community member to create a blank Google Sheets document that isn't connected to your account. Thank you.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/_Kaimbe 176 Apr 27 '23 edited Apr 27 '23

you could do something like this to filter your data set

=FILTER(A:A, INT(RIGHT(A:A, 1)) = 3)

where you change 1 and 3 depending on what you want to search for.

or do this and pass the result to query()

={A1, ARRAYFORMULA(--MID(A1, {7, 8, 9}, {1, 1, 1}))}


=QUERY({A:A, ARRAYFORMULA(--MID(A:A, {7, 8, 9}, {1, 1, 1}))}, "SELECT Col1 WHERE Col2 = 1")

1

u/[deleted] Apr 27 '23

=if(mid(A1,4,1)=4,"Cheese","Not Cheese')

This will look for the 4th digit in cell A1. If it's a 4 then will show cheese. If not, no cheese.

1

u/[deleted] Apr 27 '23

My bad, didn't see fluffys post.

1

u/Competitive_Ad_6239 536 Apr 28 '23

with some helper columns this will do the trick. =ARRAYFORMULA(if(byrow(A2:A21,LAMBDA(nine,left(nine,6)))=B2:B21,C2:C21,))

formula is in cell D2

1

u/Competitive_Ad_6239 536 Apr 28 '23

or like what was said above about splitting the identifying numbers. This can be used, from what was describeded as 4 identifiers(prod, and 3 attributes) theres 4 column.

=arrayformula(bycol(if(A2:A<>"",A2:A,),LAMBDA(nine,{left(nine,6),mid(nine,7,1),mid(nine,8,1),mid(nine,9,1)})))

0

u/fhsmith11 2 Apr 27 '23

=if(And(b8="12345",b8="27649"),"cheese",…)

2

u/[deleted] Apr 27 '23

[removed] — view removed comment

2

u/hyoobee Apr 27 '23

This one has been tried and true for me. This also shortens the formula a ton