Data generation in Excel - excel

Good morning, I am new at using excel and I'll be very thankful if someone can help (and I'm sure that the answer is easy from your point of view).
https://img15.hostingpics.net/pics/785039data.png
The screen capture reprents a simplified way of explaining what I am looking for:
For each number in the first column (which can appear more than once), I want to generate a corresponding Id (See column Id to affect which is the type of data).
We are only looking at the beginning of "Number", which can be up to 8 number is size.
Sometimes there can be tricky case, as te example starting with 40 vs 402 which are not affected to the same Id.
As I am new on excel maybe this answer or question exist but I don't know how to search/name it.
Thank you for your help, have a great day.

Tricky formula. Not exactly the prettiest thing ever but this formula works: (Line breaks added for readability)
= IFERROR(INDEX(D$2:D$7,MATCH(MAX((((A2-(C$2:C$7*10^(CEILING(LOG10(A2+1),1)
-CEILING(LOG10(C$2:C$7+1),1))))=MOD(A2,10^(CEILING(LOG10(A2+1),1)
-CEILING(LOG10(C$2:C$7+1),1))))+0)*C$2:C$7),C$2:C$7,0)),"(no match)")
A few things to note:
You didn't include cell ranges so you will have to manually change the cell ranges in the formula above to whatever your particular cell ranges are.
This is an array formula, meaning after you enter this formula into a cell, you must press on the keyboard Ctrl+Shift+Enter rather than just Enter.
The formula looks for the "strongest" match. For example, if a number is 40200000, the formula would return "Grapefruit" because it is a stronger match than "Grape".
If no match is found, I just have the formula return "(no match)" but you can obviously change that to whatever you want.
I assume this won't be an issue, but the formula will not work if any negative numbers are used.
See below, screenshot that shows formula works for your data.

You can try this array formula (click Ctrl + Shift + Enter together) from cell B2 and drag it down:
=IFERROR(INDEX(D$2:D$7,MATCH(MAX((VALUE(LEFT(A2,LEN($C$2:$C$7)))=$C$2:$C$7)*C$2:C$7),C$2:C$7,0)),"")
This will try to match the longest number (with MAX) and return the value (with INDEX/MATCH).

Related

Is there a way to add a formula to unique data points in excel?

I am trying to clean some data with this format:
A1 B1 C1
"0,1,0,E,1" "0,0,0,E" "0,1,1,1,2,E"
To obtain the information, I will need to sum up each cell individually, and then calculate the sum over a row.
So far, I have replaced all of the "E"s (for empty) with no data, which removed the E's, and I have replaced all of the commas with "+" signs to add the numbers in the cell. To run the formula of each cell, I will need to now place an "=" in front of each text string, however, if I copy it in with something like "="="&A1" the formula will not run because excel is reading the = as a letter or symbol and not an operator. Do you know of a way to fix this problem?
Thank you so much!
I think this will work for your version ...
=SUM(FILTERXML("<d><c>" & SUBSTITUTE(A1,",","</c><c>") & "</c></d>","//c"))
That's applied like below ...
... there's always someone smarter than me but that seems to work.
It’s not an in place replacement but it keeps your source data intact and provides a nice reconciliation point.
Using a separate sheet for each column of values, given data in cell A1 of
0,0,0,1,0,1,1,E,1,0
In C1, enter the formula
=IFERROR(MID(SUBSTITUTE(SUBSTITUTE($E$14,",",""),"E",""),COLUMN()-2,1)*1, "")
and drag the fill handle to to the right for as many cells as the longest number of data points you have.
Enter your SUM()formula in B1 (you can use the shortcut ALT + =).
Have you tried something like this, please refer the image, where its showing as per your required output, three alternative formulas
1.) Formula used in cell B2
=SUMPRODUCT(IFERROR(--MID($A2,ROW(INDIRECT("1:"&LEN($A2))),1),0))
2.) Formula used in cell D2
=SUMPRODUCT(IFERROR(--MID($C2,SEQUENCE(LEN($C2)),1),0))
The 2nd formula is applicable to Excel 2021 & O365 Users only
3.) Formula used in cell F2
=SUM(IFERROR(--MID($E2,ROW($1:$1000),1),0))
This is an array formula, so requires to press CTRL SHIFT ENTER !
Here is an update, the last formulas, which i have shared, shall work only when the digits are less than 10, however the present formula, shall work for all number of digits,
Formula used in cell B17
=SUMPRODUCT(IFERROR(--MID(SUBSTITUTE($A17,",",REPT(" ",100)),COLUMN(A1:Z1)*99-98,100),0))
Please adjust your range accordingly as per your data.

Excel - Highlight cell which is closer and smaller to a specific value

I would like to highlight a cell which is the closest the a specific value but still lower (below) or equal according to a formula.
For instance, if I have 14 in B4, I would like the cell 13 (or 14) highlighted but not 15 in the range.
The value I need to look for would be in B4 and the range that I must apply the highlight formula to would be L1:L371.
So far, the best result I was able to achieve was with (from what I was able to find using Google or Stackoverflow already existing content):
=SMALL($L1:$L317,COUNTIF($L1:$L371,"<="&$B$4))
Although, not only it selects the value I am looking for, it also selects all the values below.
May someone provide me some help so I can achieve the expected result please?
Thank you for your time and help, it is greatly appreciated.
Based on your description, it seems like you need to find the maximum value of a range (L1:L137) that is less than or equal to an input variable (B4) and highlight that value in the search range. Depending on what version of Excel you have, here's what you need to do:
For Excel 2019 or Excel 365
You can use the MAXIFS function. You would actually put that function in a conditional formatting rule, but more on that in just a second. As a test, put the following code in cell B5:
=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
The first argument is your "MAX_RANGE", or the range that contains the values you want to find the max of. It is also our "CRITERIA_RANGE", the second argument. The third argument is the criteria itself, which is that the search range must be less than or equal to the value in cell B4. Essentially, we are going through the list and creating a subset of numbers that are less than or equal to our search value, and discarding the rest. I assume you are aware of relative vs. absolute referencing, since you used the "$" anchor in your referenced code. If not, here's a description of the difference.
Now, the result of that formula should be the highest number in the list less than or equal to the search value, but that doesn't highlight it for us in our list. To do this we need conditional formatting. To do this, highlight your data range (L1:L137) and go to the conditional formatting drop down on the home tab of the menu ribbon. Choose "New Rule". On the dialog that pops up, choose, "Use a formula to determine which cells to format". In the formula input box, enter:
=L1=MAXIFS($L$1:$L$137,$L$1:$L$137,"<="&$B$4)
This will compare whether the value in the cell being evaluated (L1, for instance) is equal to the result of that formula we talked about above. Since L1 is only relatively referenced, this formula will work for every cell in the data range.
Now, before you hit "OK" on the dialog, select the Format button. This will allow you to adjust your highlighting and formatting as you desire. Click "OK" on the formatting dialog, then "OK" on the Conditional Formatting Rule dialog. This should now highlight any data cell that is equal specifically to the result of our formula, and not everything that's less than our value.
For Earlier Versions of Excel
The concept is the same in earlier versions of Excel, but unfortunately, the MAXIFS function is not present in these versions. Instead, we must use an array formula. Array formulas are a whole other can of worms, but ExcelJet is an excellent resource. In fact, they talk about this very issue, here.
Unfortunately, we can't put the array formula in the conditional formatting formula like we did above, so we'll need to put this formula on a cell in the worksheet, then the conditional formula should reference that new cell. So in cell B5, if you put:
=MAX(IF(L1:L137=B4,L1:L137)
And then, instead of pressing Enter, you must press Ctl + Shift + Enter
This keyboard combination will tell Excel that you are trying to enter an array formula. If you don't press these keys, then the formula will error. Once you have entered the array formula, if you put your cursor in cell B5, you will see the formula bar at the top has added curly braces ({ , }) around the formula to look like
{=MAX(IF(L1:L137=B4,L1:L137)}
This leads to the same result as above, but is just achieved slightly differently. Now, following the same process described above for conditional formatting, you will simply set the formula to:
=L1=$B$5
And that should be it! Hope this helps!

How to define a range, using an Excel formula

In order to do some calculations on averages and differences of values in columns, I've defined a name, based on a range, but it seems to be completely going berserk:
I have a cell (D13), defined as Header_First _Answer, which contains the title of the column, and I have a value (currently being 69), which contains the number of entries, called Total_Count.
I've defined the entries of that column as another name: "All_First_Answered_Dates", defined as =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (start by the first entry under Header_First_Answer, take up to 69 entries, and define a range out of this).
In cell G5, I'm using that name in order to do some calculations (calculating averages), but this seems not to work (there is a #Value error).
After second comment from Rory: G5 formula and first formula evaluation result:
Formula:
=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)
First evaluation result:
=AVERAGE(IF(ISBLANK(#Value!);TODAY();All_First_Answered_Dates) - All_Start_Dates)
Hence, my conclusion:
After some checking I've found out that this is due to the name "All_First_Answered_Dates", which seems to be interpreted one time too many (or how do I explain this):
In different cells, I've entered the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0) (which is exactly the meaning of "All_First_Answered_Dates"), and every time, using the Evaluate Formula feature, I see that the last but one result is correct: $D$14:$D$82. However, after that, another evaluation is done, turning this value into 43283 (in case the formula is entered in "J14"), 43300 (in case the formula is entered in "J15"), ..., and in case I enter this formula in a cell with row number lower than 14, I have the error value #Value (which explains the wrong result in cell G5).
If I simply put the formula =$D$14:$D$82 in any of the mentioned cells, then the content of some cells in column D are shown (which are dates, not values like 43283 or 43300).
It appears that declaring a range as =x:y, where x and y are formula results, is not working.
Does anybody know how I can define a range as a formula, which I can then use in order to define in a name?
I can imagine my explanation being quite complicated without an image, hence the attached screenshot. In there:
In cell J13, there is the formula =OFFSET(Header_First_Answer;1;0):OFFSET(Header_First_Answer;Total_Count;0).
In cell J14, there is the same formula.
In cell K14, there is the formula =$D$14:$D$82.
For completion purposes, hereby a screenshot of the name manager, containing both mentioned names (the ones, selected in the name manager):
Edit after first comment:
The idea behind the range is the following:
1. Take the first row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;1;0)
2. Take the Total_Count's row under Header_First_Answer, do not take any other column : OFFSET(Header_First_Answer;Total_Count;0)
3. Define a range, based on those two cells, by putting a semicolon between them.
I was not aware of the height and width features of the Offset() worksheet function. I've implemented them, which makes the formulas much easier.
Unfortunately the problem still persists.
Thanks in advance
Dominique
I've just found the answer of what was going wrong:
The formula was meant to be an array formula. Something went wrong and while trying to debug, I accidently re-formatted the formula into a normal formula (I must have pressed "ENTER" instead of "Ctrl" + "Shift" + "ENTER") at some point.
I have re-applied array formula (using "Ctrl" + "Shift" + "ENTER"), getting a formula like:
{=AVERAGE(IF(ISBLANK(All_First_Answered_Dates);TODAY();All_First_Answered_Dates) - All_Start_Dates)}
(mind the braces {, })
Now everything is working fine.

Excel How to find more values that contain values in the cell next to them?

I want to use the Index formula to list data in my excel sheet.
I want to list the data of the column A that contains "finished" in the corresponding cells in column E.
Currently I'm using the following formula:
=INDEX(IMs!A:A;MATCH("finished";IMs!E:E;0))
The problem is, only the first value appears. I want to list ALL of them.
Is it possible with the vlookup formula?
Thank you very much in advance.
Kind regards,
Vanessa
First enter this formula in B1:
=COUNTIF(IMs!$E:$E,"Finished")
Then enter this array formula** in your first cell of choice:
=IF(ROWS($1:1)>$B$1,"",INDEX(IMs!$A$1:$A$1000,SMALL(IF(IMs!$E$1:$E$1000="finished",ROW(IMs!$E$1:$E$1000)-MIN(ROW(IMs!$E$1:$E$1000))+1),ROWS($1:1))))
Copy this formula down (though not the one in C1) until you start to get blanks for the results.
If the upper row reference that I chose (1000) is not sufficiently high, then change it as required. Note, however, that since this is an array formula, it is not recommended that you make this upper bound too high (and certainly don't reference entire columns!), since this will have a significantly detrimental effect on spreadsheet performance.
From your post, it also appears that you are using a version of Excel in which the argument separator in formulas is not the comma but the semi-colon. If this is indeed the case then you will need to make the necessary amendments to the formulas I provided.
Regards
**Array formulas are not entered in the same way as 'standard' formulas. Instead of pressing just ENTER, you first hold down CTRL and SHIFT, and only then press ENTER. If you've done it correctly, you'll notice Excel puts curly brackets {} around the formula (though do not attempt to manually insert these yourself).

How to Count number of text instances in excel?

I have a table of my workdays and I want to count instances of word 'work' in each row.
I have a table like this:
I used this code in J1 cell but it doesn't work.
=SUM(IF(2:2 = "Sleep",1,0))
I have found this formula in microsoft's website but it doesn't work.
What is causing this problem?
You need to use the COUNTIF function.
=COUNTIF(C2:I2,"Sleep")
This goes in Cell J2
From Excel's Help
The COUNTIF function counts the number of cells within a range that meet a single criterion that you specify. For example, you can count all the cells that start with a certain letter, or you can count all the cells that contain a number that is larger or smaller than a number you specify.
When in doubt, press the magic button F1 in Excel. :)
Just came across a similar thing in a worksheet and came to google before I remembered why it didn't work.
The countif statement above is perfectly fine, however the original formula given wouldn't have worked as to use a sum in this way means you have to make it an array or CSE Formula instead.
So, if you come across this, click in the formula bar and press ctrl + shift + enter and it should sort the whole thing out.

Resources