I want to give a two-column Excel file as input to my script. But I need a two-column Excel file to have one feature: the second column must have 10 characters. Because the number of rows in the Excel file is large, I can not manually edit every cell in the second column.
So I need to put a control function in Excel to check the second column, so that it counts the number of characters in each cell in the second column and adds zero to the right of it, which is less than ten characters.
Based on my search, I realized that I could use the definition of the condition and the Len function, but the output was not what I wanted.
Full ID Expected Result
15 0000000015
159 0000000159
16 0000000016
43 0000000043
4329 0000004329
What I had tried :
=Right(A2,LEN(A2)+8)
but it was wrong.
How can I get my expected results in like the top example?
One way is to use Rept to repeat the correct number of zeroes:
=REPT("0",10-LEN(A2))&A2
Or simpler to use Text:
=TEXT(A2,"0000000000")
The nearest to your original formula would be something like
=LEFT("0000000000",10-LEN(A2))&A2
Or better the formula suggested by #JvdV
=RIGHT("0000000000"&A2,10)
To be honest I wasn't sure if by simply formatting the data as "0000000000" the zeroes would be preserved if (for example) you wrote the sheet out as a CSV, but I have tested it just to make sure and in fact they are so I think this remains the optimal solution.
Test Sheet
Resulting CSV
Related
I need help in writing a formula in cell b7. The formula must look to the right and multiply the nonempty cells by the corresponding value in row 3, and I would like to sum up the results.
File link provided.
FILE LINK
ScreenShot
Please see my comment to your original post.
That said, I will try to explain how to approach this as I think you intend. (This solution will be a Google Sheets solution which will not work in Excel.)
The first thing you will need to do is to delete everything from Row 11 down: all of your examples and notes must be deleted for the following proposed formula to work correctly.
Once you have no superfluous data below your main chart, delete everything from B6:B (including the header "Total").
Then, place the following formula in cell B6:
={"TOTAL"; FILTER(MMULT(C7:G*1, TRANSPOSE(C$3:G$3*1)), A7:A<>"")}
This formula will return the header text "TOTAL" (which you can change within the formula itself if you like) followed by the calculation you want for each row where a name is listed in A7:A.
MMULT is a difficult function to explain, but it multiplies one matrix ("grid") or numbers by another matrix ("grid") and returns the sum of all products per row (or per column, depending on how you set it up) —— which is what you are trying to do.
MMULT must have every element of both matrices be a real number. To convert potential nulls to zeroes, you'll see *1 appended to each range (since null times 1 is zero).
This assumes that all data entered into C7:G and C3:G3 will always be either a number or null. If you enter text, you'll throw the formula into an error. If you think accidental text entries in those ranges are possible, use this version instead:
={"TOTAL"; FILTER(MMULT(IFERROR(C7:G*1, ROW(C7:G)*0), TRANSPOSE(IFERROR(C$3:G$3*1, COLUMN(C$3:G$3)*0))), A7:A<>"")}
The extra bits use IFERROR to exchange error-producing entries with zeroes, since MMULT must have every space in both matrices filled with a real number.
I have some data in Col"K" where from i am just trying to get the left characters as i tried in Col"H" using formula.
But what i used is Left function like =Function(cell,10) that is not the correct way characters can be more than 10 or less than 10.
1st formula should be dynamic to get the left numeric values.
2nd Formula should copy and paste the same numeric values until next value comes as available in Col"I"
I tried to make it but what i can do is to create left function and do not know how to develop it dynamic.
Any help will be appreciated.
Sheet Link
https://docs.google.com/spreadsheets/d/1nJZeWDZ0EWgmWB0z17xU93fjIOFsu46EL37IJqJzZ_0/edit?usp=sharing
This formula should do the job.
[J2] =IFERROR(TRIM(LEFT(L2,FIND("-",L2)-1)),J1)
Note that it will fail if placed in row 1 and there is no dash in L1.
Use find function to get numeric characters length.
=iferror(trim(left(L3,FIND("-",L3)-1)),M2)
Here we are finding the separator "-" in your text and it gives us index number of separator.
Then picking text from start to before index number i.e., Numeric value and removing blank spaces, if any, using trim function. If we don't have number/separator in the text then showing previous cell value using iferror function. So, Make sure first row always has numeric value.
Same has implemented in the sheet you have shared
As per the latest data I have updated my answer as below , now it is checking output is numeric or not:
=IF(COUNT(FIND({0,1,2,3,4,5,6,7,8,9},J9))=0,K8,TRIM(LEFT(J9,FIND("-",J9)-1)))
Question: Is the COUNTIF function working inconsistent with different data types and cell formats?
The situation:
Column A contains manually created numbers (to be used in SAP). The numbers are 18 characters long, don't contain any non digit chars. The cell format has to be Text as we would face more issues down the line if it wouldn't. If I apply the formula =COUNTIF(A:A;A2) the result is as shown in column C. However this obviously not the correct result.
Another example with "real" test data from a system extract:
The issue here is, that the COUNTIF function sometimes returns the correct result, sometimes a wrong result. I cannot figure out why its working the way it does.
Also I did not find any satisfying result somewhere else on the Internet. If I missed something, please let me know.
As a side note: If I transfer the data into a PIVOT table it always shows the correct results.
Problem:
This will most likely be due to floating point errors.
Excel's COUNTIF function will try to handle these values in A column as numbers. Because Excel uses IEEE 754 specification on how to store and calculate floating-point numbers, Excel therefore stores only 15 significant digits in a number, and changes trailing digits after the fifteenth place to zeroes. Source.
For example:
541235479876536549 will become 541235479876536000
541235479876536550 will become 541235479876536000
541235479876536551 will become 541235479876536000
541235479876536552 will become 541235479876536000
That would mean your values are 3 digits too long to be handled accurately. In this example, the unique values will all be counted 4 times using COUNTIF.
Removing the last three digits from your string should therefor make the COUNTIF behave as expected. However, this will still give you unwanted results as you don't want to mess with the original data.
Solution:
If using a pivot table (which probably works as it should pick up the data as text) is not what you want, maybe you can use:
=SUMPRODUCT(--(A$2:A$11=A2))
Note: On a large dataset, array-formulas might slow down your
workbook significantly!
Furthermore, COUNTIF is not the only function that would suffer from this behaviour. The scope of this problem included functions like SUMIF, SUMIFS, COUNTIF, COUNTIFS, AVERAGEIF, and AVERAGEIFS. Source
I am trying to obtain the highest and the lowest values within a data set and record each instance. I have used the following spreadsheet to do this.
I want to obtain the lowest occurrence and if there are one or more values that are the same it will list those values too. However, when I use what I have I cant get the numbers to stop listing.
I am Assuming this is because The numbers are not the same exact values to the number of decimal places the original data comes from. e.g. the lowest value is 21.5 but the raw data gives it to 21.498 etc.
I tried using the Round function but it merely changes the formatting of the cell.
Has anyone found a way around this?
*Edit*****
I only want to report the lowest value, and if there are multiple occurrences of the same number (to one decimal place) then record those as well. The issue is that I don't know how to tell excel to stop the list if the values are the same to 1 decimal place. I tried the round function but it only changes the formatting of the cell not the actual number so excel thinks they are different values. I am not sure how to get this to work.
G3 is the top cell with =IFERROR(SMALL($C$3:$C$101,A3),"") in it.
=IFERROR(SMALL($C$3:$C$101,A3),"")
=IFERROR(IF(SMALL($C$3:$C$101,A4)=G3,"",SMALL($C$3:$C$101,A4)),"")
the data is;
And I need the highest and lowest data to 1 decimal place.
This should fix it:
G3:
=IFERROR(ROUND(SMALL($C$3:$C$101,A3);1),"")
From G4 onwards:
=IFERROR(IF(ROUND(SMALL($C$3:$C$101,A4);1)=G$3,"",ROUND(SMALL($C$3:$C$101,A4);1)),"")
You can use an Array function (entered with Ctrl+Shift+Enter):
=SMALL(ROUND($C$3:$C$20,1),A3)
And for the matching serial number:
=INDEX($B$3:$B$20,MATCH(SMALL($C$3:$C$20,A3),$C$3:$C$20,0))
Here are the results (formatted with 3 decimal places just to prove the values are properly rounded):
I'm having an excel column range (including blank cells) something like:
00EGB00-GE001
00EGB00-GE001
00EGB00-GE001
00EGB00-GE001
00EGB00-GE002
00EGB00-GE002
00EGB00-GE002
00EGB00-GE002
00EGD20-GD101
What I need is to Count total number of similar values and I'm stuck with the logic for counting total unique "similar" values... example "GE" & "GD" separately.
How to count total number of unique "GE" values in the list?
I thought =COUNTIF(B:B,"*GE*") should work but it does not. It gives total count of "GE" but I need to find unique count. Example GE001 & GE002 should be considered as 2 values in total.
Kindly help
EDIT AGAIN: Given further clarification below, and assuming that the data always has the same number of digits, one way to do it is by putting this in Column B:
=RIGHT(A1,5)
Then, if you have Excel 2007 or up, Copy and Paste Values and use Remove Duplicates to leave you with the unique values. Then remove the items with GD, either manually or using a formula.
In this case, the output is:
GE001
GE002
In this case, you can easily see that it's 2. If you have lots of values, you can use COUNTA. Is that what you want?
YET ANOTHER EDIT BASED ON LAST COMMENT: this is probably getting closer:
=SUMPRODUCT(--(MID(A1:A9,9,2)="GE"),1/COUNTIF(A1:A9,A1:A9))
Where the "GE" is hard-coded in the formula above you could also substitute a cell reference where you can alter the value.
Or, if you don't know where the text you want will be exactly because the number of characters change, this will work (but you'd need to be careful with what you were searching on because it might repeat somewhere else in the string):
=SUMPRODUCT(--(ISERR(SEARCH("GE",A1:A9))<>TRUE),1/COUNTIF(A1:A9,A1:A9))
Again, you can replace the "GE" with a cell reference.
As discovered below, though -- blank cells will cause this to fail. There IS almost definitely a way to cater for them (maybe using a FREQUENCY based Array Formula), but if you can live with cleaning out the blank cells then that would be one way of doing it.
LAST EDIT: this will account for blank cells. It is an Array Formula, and CAN be used on whole columns, but that will be quite slow as it takes up a fair bit of calculation effort:
{=SUMPRODUCT(--(MID(A1:A9,9,2)="GE"),IF(ISBLANK(A1:A9),1,1/COUNTIF(A1:A9,A1:A9)))}
As it's an Array Formula, use Ctrl + Shift + Enter to input it.