I have the below issue to consider in one of my worksheets.
Column A contains identifiers from a list, Columns B to F contain various data matching each code.
I have an additional column(M) which contains my own identifiers. What I want to achieve is to match the my identifiers with the ones from the list so I can pull the data from columns B to F according to my codes. These identifiers are mostly the same, with only slight variations.
I've tried with vlookup and wildcard, but I've only been partially successful.
Sample data looks like this with below formula in column M:
I'm using =VLOOKUP(A2&"*",mockup2,1,0) as a formula in "Matched" column; mockup2 is B2:B9 in the given sample.
However, it fails when there's not an exact match found, using "TRUE" seems to break the other ones that are working fine.
What I'm looking to achieve should look like below:
A few things to note, is that the full data contains more identifiers which are different from what is shown in the sample. The only thing that shows up in multiple identifiers is -C, an example of more identifiers would be BLK, CDAS, BLK S, BLK A, KYUIS-C, KYUOXAR T etc.
Is there a way to achieve what I want with Excel?
https://photos.app.goo.gl/tmRJfQK6DM2Hu7nYA
=IFERROR(INDEX(SORTBY($B$2:$B$9,LEN($B2:$B9),-1),MATCH(1,(LEFT(A2,LEN(SORTBY($B$2:$B$9,LEN($B$2:$B$9),-1)))=SORTBY($B$2:$B$9,LEN($B$2:$B$9),-1))*(SORTBY($B$2:$B$9,LEN($B$2:$B$9),-1)=LEFT(A2,LEN(SORTBY($B$2:$B$9,LEN($B$2:$B$9),-1)))),0)),"")
I don't know if it's to be entered as an array function (ctrl + shift + enter, since SORTBY is an array function already, but my version of excel does not support this yet. This is available in Office 365.
I sorted the data by length manually in the snipe, but I think the sortby will work without having to pet the data.
Let me know if it works for you.
Related
I have a table of data with many data repeating.
I have to sort the rows by random, however, without having identical names next to each other, like shown here:
How can I do that in Excel?
Perfect case for a recursive LAMBDA.
In Name Manager, define RandomSort as
=LAMBDA(ζ,
LET(
ξ, SORTBY(ζ, RANDARRAY(ROWS(ζ))),
λ, TAKE(ξ, , 1),
κ, SUMPRODUCT(N(DROP(λ, -1) = DROP(λ, 1))),
IF(κ = 0, ξ, RandomSort(ζ))
)
)
then enter
=RandomSort(A2:B8)
within the worksheet somewhere. Replace A2:B8 - which should be your data excluding the headers - as required.
If no solution is possible then you will receive a #NUM! error. I didn't get round to adding a clause to determine whether a certain combination of names has a solution or not.
This is just an attempt because the question might need clarification or more sample data to understand the actual scenario. The main idea is to generate a random list from the input, then distribute it evenly by names. This ensures no repetition of consecutive names, but this is not the only possible way of sorting (this problem may have multiple valid combinations), but this is a valid one. The solution is volatile (every time Excel recalculates, a new output is generated) because RANDARRAY is volatile function.
In cell D2, you can use the following formula:
=LET(rng, A2:B8, m, ROWS(rng), seq, SEQUENCE(m),
idx, SORTBY(seq, RANDARRAY(m,,1,m, TRUE)), rRng, INDEX(rng, idx,{1,2}),
names, INDEX(rRng,,1), nCnts, MAP(seq, LAMBDA(s, ROWS(FILTER(names,
(names=INDEX(names,s)) * (seq<=s))))), SORTBY(rRng, nCnts))
Here is the output:
Update
Looking at #JosWoolley approach. The generation of the random sorting can be simplified so that the resulting formula could be:
=LET(rng, A2:B8, m, ROWS(rng), seq, SEQUENCE(m), rRng,SORTBY(rng, RANDARRAY(m)),
names, TAKE(rRng,,1), nCnts, MAP(seq, LAMBDA(s, ROWS(FILTER(names,
(names=INDEX(names,s)) * (seq<=s))))), SORTBY(rRng, nCnts))
Explanation
LET function is used for easy reading and composition. The name idx represents a random sequence of the input index positions. The name rRng, represents the input rng, but sorted by random. This sorting doesn't ensure consecutive names are distinct.
In order to ensure consecutive names are not repeated, we enumerate (nCnts) repeated names. We use a MAP for that. This is a similar idea provided by #cybernetic.nomad in the comment section, but adapted for an array version (we cannot use COUNTIF because it requires a range). Finally, we use SORTBY with input argument by_array, the map result (nCnts), to ensure names are evenly distributed so no consecutive names will be the same. Every time Excel recalculate you will get an output with the names distributed evenly in a different way.
Not sure if it's worth posting this, but I might as well share the results of my research such as it is. The problem is similar to that of re-arranging the characters in a string so that no same characters are adjacent The method is just to insert whichever one of the remaining characters (names) has the highest frequency at this point and is not the same as the previous character, then reduce its frequency once it has been used. It's fairly easy to implement this in Excel, even in Excel 2019. So if the initial frequencies are in D2:D8 for convenience using Countif:
=COUNTIF(A$2:A$8,A2)
You can use this formula in (say) F2 and pull it down:
=INDEX(A$2:A$8,MATCH(MAX((D$2:D$8-COUNTIF(F$1:F1,A$2:A$8))*(A$2:A$8<>F1)),(D$2:D$8-COUNTIF(F$1:F1,A$2:A$8))*(A$2:A$8<>F1),0))
and similarly in G2 to get the ages:
=INDEX(B$2:B$8,MATCH(MAX((D$2:D$8-COUNTIF(F$1:F1,A$2:A$8))*(A$2:A$8<>F1)),(D$2:D$8-COUNTIF(F$1:F1,A$2:A$8))*(A$2:A$8<>F1),0))
I'm fairly sure this will always produce a correct result if one is possible.
HOWEVER there is no randomness built in to this method. You can see if I extend it to more data that in the first several rows the most common name simply alternates with the other two names:
Having said that, this is a bit of a worst case scenario (a lot of duplication) and it may not look too bad with real data, so it may be worth considering this approach along with the other two methods.
I would like to filter a dataset considering several filter condition that can change dynamically based on a list of possible values. I have filter criteria team which have the following values: Team A, Team B, ALL, where ALL is a wildcard representing all teams. For the second criteria release, in case I want to include more than one release in the filter, the values are separated by comma, for example: Release: A, B, A,B, where the last one means to include both release A and B. I was able to make it works except for the case when the release value is A,B.
I think I should use: TRANSPOSE(TEXTSPLIT(B4,", ")) to obtain in a column the list of values and then in some how (maybe using MMULT) to be able to add the filter condition per each row, but I was not able to do it (in Excel, because using Google Spreadsheet I was able to do it using a query function)
The following formula for single release value works for both criteria:
FILTER(D3:H8, (IF(B3="ALL", D3:D8<>"*",D3:D8=B3)) * (E3:E8=B4))
but it doesn't work for the general case where release values are more than one.
I am looking for a solution that would not require a VBA script
Here is the sample file:
Here is a link to the sample excel file:
https://1drv.ms/x/s!AlZxw2GG3C7IhyhTnBFbln1G8fOj?e=C8OUxn
This appears to work:
=FILTER(D3:H9, (IF(B3="ALL", D3:D9<>"*",D3:D9=B3)) * (ISNUMBER(XMATCH(E3:E9,FILTERXML("<c><e>"&SUBSTITUTE(B4,", ","</e><e>")&"</e></c>","//e"),0))))
(if you decide to have multiple releases delimited by a comma without the space then the SUBSTITUTE() function will require to be updated accordingly)
Expanding the idea suggested by: #scottCraner, this would be the solution for the release condition:
ISNUMBER(MATCH(E3:E9,TRANSPOSE(TEXTSPLIT(B5,", ")),0))
so the entire formula will look like:
=FILTER(D3:H9, (IF(B3="ALL", D3:D9<>"*",D3:D9=B3)) *
(ISNUMBER(MATCH(E3:E9,TRANSPOSE(TEXTSPLIT(B4,", ")),0))))
Note: it works also removing the TRANSPOSE function, i.e.:
=FILTER(D3:H9, (IF(B3="ALL", D3:D9<>"*",D3:D9=B3)) *
(ISNUMBER(MATCH(E3:E9,TEXTSPLIT(B4,", "),0))))
Here is the sample solution:
I've included example screenshots and the forumlas bellow. I'm basically trying to run a list of Competitors against a list of searches. The competitor list is static and the searches list will grow and change overtime.
I'm finding it challenging to get consistent results with the search formula. It either is too loose (example A) or too strict (example B).
Is there a way to use the formula to exact match whole words in a text string? Or do I need to get sneaky with a VBA (something I'm not too familiar with). Or should I be doing this in another program?
Thanks!
Example A
So here, my formula works and says that someone searched containing avamere. However, It gives me a false positive on "roseville communities" because it has seville in roseville.
Example A Formula:
SUMPRODUCT(--ISNUMBER(SEARCH($C$2:$C$5,B2)))>0
Example B
So I tried to normalize the competitors with spaces:
Now they're all false.
Example B Formula:
SUMPRODUCT(--ISNUMBER(SEARCH(" "&$C$10:$C$13&" ",B10)))>0
User Form Input
Loading Kit Reference
I have several columns of user input which needs to match each column in a reference sheet to return a given drawing number.
My initial attempt:
=INDEX('Loading Kits'!A$2:A$113,MATCH(1,('Shop Orders'!B5='Loading Kits'!C$2:C$113)*('Shop Orders'!E5='Loading Kits'!D$2:D$113)*('Shop Orders'!G5='Loading Kits'!E$2:E$113)*('Shop Orders'!H5='Loading Kits'!F$2:F$113)*('Shop Orders'!I5='Loading Kits'!G$2:G$113),0))
This works great when reference sheets only have one option for size ('Shop Orders'!B5='Loading Kits'!C$2:C$113).
How do I create a match when there are several (up to 6) options listed in one column delimited by commas (24C,24D,26A,26B,26AV,26BV)?
One of the few exceptions where I would say concatenation while using INDEX and MATCH would be safe to work with IF your values are concatenated through comma's without a space (otherwise the formula would be a little bit different). But let me give you a minimal example of how to get something like that to work:
The formula in F3:
=INDEX(A2:A4,MATCH(1,INDEX((B2:B4=F1)*(ISNUMBER(FIND(","&F2&",",","&C2:C4&","))),),0))
If your values follow eachother by comma space you obviously have to concatenate differently:
=INDEX(A2:A4,MATCH(1,INDEX((B2:B4=F1)*(ISNUMBER(FIND(", "&F2&",",", "&C2:C4&","))),),0))
I'm using excel 2007.
I've a list of tasks (200-500) that I need to group in different category/section etc (multiple filters). Whole data is in excel table so I can apply Excel's build-in table filters to display exact data that I need.
However it is always difficult to apply multiple filter to display expected data, specially as I need to do it very frequently. To make things simple I'm planning to number each record like
a.b.c.d.e.f
Where a, b, c, d, e, f are simple numbers. List looks like:
1
1.1
1.2
1.2.1
1.2.1.1
1.2.2
1.3
& so on.
Problem is, Excel take it as number with single decimal but as soon as I add second decimal, excel treat it as text, which is obvious in general behavior.
However, as special case, I need excel treat both as number or text. Number is preferable as I want to sort them, which might be difficult as a text.
To make the things little more complex, while filtering in table, I require if I can add some formula to filter results like 1.* should display all numbers starts with 1.
Is it possible with excel's default behavior, without VBA?
If no, is it possible with VBA? If yes, any clue is appreciated. I don't need whole program as I can write basic VBA program, just a clue how it can be done?
I sort mine by adding a helper column that adds a letter to the front and sort on that. E.g. 1 becomes f1, 1.1 becomes f1.1 etc. Then all are sorted as text.
You can use the formula ="f" & A1.
My sample:
Then the data sorted:
And the filter:
If I were to try this without VBA, my first step would be to use the sort to columns function on the data tab.
Next make sure all empty spaces in your data are filled with zeros.
Then sort the data by column
as long as you left your original data in the same row as the sorted data (I didn't in the images posted to focus on the process), your items should now be in order.