Apr 19 2023 08:30 AM
I have been playing around this for a wile and cannot get it working.
I currently use =MID(B2,FIND("x",B2,1),15) (but this is very basic and i have to do alot of editing as it also pulls over "X" (E.G. X 13, X13, x13 - P1C)
User x 3 - P1C > Answer 3
Users - Multiple x7 - BA2000 X7 > Answer 7
Users x13- BA2000 13x > Answer 13
Users > Blank
if also possile if the number come before x
Users 13x- BA2000 13x > Answer 13
Apr 19 2023 09:22 AM
Is it possible to prevent this from happening in the first place, rather than try to deal with it after the fact?
You seem to be wanting to extract a meaningful number from entries made by users, entries that follow (from appearances in your example) no reliably predictable pattern. That means that no single formula is going to be reliable over the long term. Even in the examples you give, there are numbers other than the ones you give as "answer" -- specifically the 2000 figure that appears a couple of times and the 1 from "P1C." It's possible that those are product codes, I suppose, so you don't even see them as numbers, but the computer would have to "know" that.......
In any event, it's generally wiser to prevent problems from arising rather than fix or correct after the fact. Is that within the realm of possibilities in your situation? If not, why not?
Apr 19 2023 11:01 AM
thanks. I thought it may of been a long shot.
I should have said I only need the number next to “X”
sadly we cannot fix this issue of the way the data comes in. As it comes from a customer.
Apr 19 2023 11:26 AM
I thought it may of been a long shot.
I suspect it's entirely doable; Excel is remarkably powerful. I'm going to leave that to some of the others here who are really adept at that kind of text-to-number manipulation.
But I do want to press a bit harder on my first point. You wrote:
sadly we cannot fix this issue of the way the data comes in. As it comes from a customer.
If the former, it should be easy to request that that person separate the number
--if in Excel--in a cell that uses data validation to ensure a number and only a number is entered
--if not in Excel, somehow separated and distinct from the rest of the accompanying tex
If it's multiple customers, I'd still be curious what the process is by which that "messy data" (a) arrives, and (b) ends up in an Excel spreadsheet. If I were in your shoes, I'd be looking for ways to have it arrive "clean." As the expression goes, "an ounce of prevention is worth a pound of cure."
Apr 19 2023 11:40 AM - edited Apr 19 2023 11:58 AM
try this:
=LET(in,C1,
notvals,IFERROR(TEXTSPLIT(in,{",",".","x"," "}, CHAR(SEQUENCE(10, , 48)), 1),CHAR(1)),
vals,TEXTSPLIT(in, notvals,,1),
xVals, SUBSTITUTE(FILTER(vals,ISERROR(--vals),""),"x",""), out,INDEX(FILTER(xVals,NOT(ISERROR(--xVals)),0),1),
out)
note I give credit to @davidleal for his answer in another thread making this option much easier
Note 2: i changed it to accommodate a space between the x and the number, and in case an "x" appears before the first x123
Apr 19 2023 07:04 PM
Apr 19 2023 10:26 PM
A variant:
in B2:
=LET(
split, TEXTSPLIT(A2,{" ","x","-"}),
num, NUMBERVALUE(FILTER(split, split<>"")),
TAKE(FILTER(num, ISNUMBER(num),""),,1)
)
Apr 20 2023 01:05 AM
Apr 20 2023 04:47 AM
=LET(
split, TEXTSPLIT(SUBSTITUTE(SUBSTITUTE(A2,"x ","x")," ","-"),"-",,TRUE),
IFNA(NUMBERVALUE(SUBSTITUTE(INDEX(split,,XMATCH("*x*",split,2)),"x","")),"")
)
Apr 20 2023 05:13 AM
Apr 20 2023 05:20 AM
Apr 20 2023 05:32 AM
- Could you supply a list of ALL your variations please?
- With 8k rows/report a Power Query approach would probably be more efficient, assuming you run Excel >/= 2016 / Windows?
Apr 20 2023 05:34 AM - edited Apr 20 2023 05:50 AM
actually it isn't about it being at the end it is because you have numbers before AND after the "x" so both of the above come back with "2000 5" and because of that it isn't a valid result.
IF "x 3" is valid but "3 x" is NOT valid then this will work:
=LET(in,A1, tag, "x",
notvals,IFERROR(TEXTSPLIT(in,HSTACK({",","."},tag,tag&" "), CHAR(SEQUENCE(10, , 48)), 1),CHAR(1)),
tagVals,TEXTSPLIT(in, notvals,,1),
vals, SUBSTITUTE(FILTER(tagVals,ISERROR(--tagVals),""),tag,""),
out,IFERROR(INDEX(FILTER(vals,NOT(ISERROR(--vals)),0),1),0),
out)
note, YOU can customize this. The part in line 2: HSTACK({",","."},tag,tag&" ") are all the non-number exception that should be included where tag is defined as "x" in line 1. So in this version I allow numbers (including decimal and commas) next to "x" or after "x" with a space. You can 'play' with this by changing the "out" on line 6 to "tagVals" to see what it finds as 'tagged values in the string' or to "vals" to see which of those 'tagVals' it thinks are potential after removing actual numbers and removing the 'tag' value and then finally 'out' which then returns the 1st found 'vals' that is valid number.
Apr 20 2023 06:01 AM
Apr 20 2023 06:28 AM
SolutionApr 20 2023 06:49 AM
Apr 20 2023 06:28 AM
Solution