Insert a 0"zero" infront of number for specify number sequences - excel

I have this data
Name | Code | Price
XXX 102 1000
YYY 4321 1150
ZZZ 202 1150
AAA 123 1000
I can now Add concatenate and Add 0 in front of Code which makes
0102
04321
0202
0123
Now here the problem lies. I dont want that 0 in front of 4321 . I want 0 only infront of 3 digit numbers not more than 3 digit.

Right click on Column, go to Format cell-->Custom and write 0000 in the type and click on Ok
Simplest and easy solution

Assuming the '102' data is located at B2, just type :
=IF(len(B2)<=3,"0"&B2,B2)
will do. Alternatively, using concatenate() function you may do it like this :
=IF(len(B2)<=3,CONCATENATE("0"&B2),B2)

Assuming you have codes in B column
if(len(b2)=3,concatenate("0",b2),b2)

If you want to write formula then this would be better,
=REPT(0,4-LEN(A1))&A1

Related

Google sheets formula to get the Top 5 List With Duplicates

I'm trying to compile a best 5 and worst 5 list. I have two rows, column B with the number score and column C with the name. I only want the list to include the name.
In my previous attempts the formula would get the top/bottom 5 but as soon as a duplicate score appeared the first known name with that value would just repeat.
Here is my data
26 Cal
55 John
55 Mike
100 Steve
26 Thomas
100 Jaden
100 Jack
95 Josh
87 Cole
75 Brett
I've managed to get the bottom 5 list formula correct. This formula works perfectly and includes all names of duplicate scores.
Example of what I get:
Cal
Thomas
John
Mike
Brett
=INDEX($C$56:$E$70,SMALL(IF($B$56:$B$70=SMALL($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=SMALL($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=SMALL($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Here is the formula I've tried to get the top 5 - however I keep getting an error.
=INDEX($C$56:$E$70,LARGE(IF($B$56:$B$70=LARGE($B$56:$B$70,ROWS(E$2:E2)),ROW($B$56:$B$70)-ROW($B$56)+1),SUM(IF($B$56:$B$70=LARGE($B$56:$B$70,
ROWS(E$2:E2)),1,0))-SUM(IF($B$56:$B$70<=LARGE($B$56:$B$70,ROWS(E$2:E2)),1,0))+ROWS(E$2:E2)))
Example of what I'm looking for
Steve
Jaden
Jack
Josh
Cole
You can set two queries like this for both cases:
=QUERY(B56:C70,"Select C order by B desc limit 5")
=QUERY(B56:C70,"Select C order by B limit 5")
Use SORTN() function like-
=SORTN(A1:B10,5,,1,1)
To keep only one column, wrap the SORTN() function with INDEX() and specify column number. Try-
=INDEX(SORTN(A1:B10,5,,1,1),,2)

How to swap characters around inside a column in EXCEL?

Specifically, I know ahead of time I only need to swap position 1 and 2 with 4 and 5.
2 Examples:
HEART
New output:
RTAHE
12734
New output:
34712
There is probably more than a handful of ways to do this. If you're interested in a formula, here is one way to go about it:
=RIGHT(A3,2)&MID(A3,3,LEN(A3)-4)&LEFT(A3,2)
Seems to be working on some test data I threw together.
A bit more robust, as suggested by #Rafalon:
=MID(A3,4,2)&MID(A3,3,1)&LEFT(A3,2)&MID(A3,6,LEN(A3))
Produces following results:
Input
1
12
123
1234
12345
123456
1234567
Output
1
12
312
4312
45312
453126
4531267

Group/Sort Data using helper column

I'm looking to find a way to group/sort data based on a 2 serial numbers, in this case called Demand Number and Supply Number.
The logic I'm trying to apply is if an items supply number matches the demand number of another item then it should be shown underneath it for example if you were to sort the data shown below:
You would get the following result:
I think I will need to use some helper columns, to apply 'levels' to the items but I'm really not sure where to go.
Thanks for the help!!
Note if there is not way to achieve the sort as shown above, this sort would also be suitable:
Here is the data as text:
Item ID Demand Number Supply Number
Nut 10 1005 10055
Nut 10 10056 10087
Nut 10 1005 100585
Washer 40 10056 10095
Washer 40 1005 154899
Suspension 9 1001 1005
Engine 15 1001 10056
Car 66 18996 1001

finding the cheaper price in excel

I have a table in the following format
ID Price
123 £12.99
123 £13.00
123 £12.99
456 £21.99
456 £20.90
789 £18.99
789 £16.99
I'm trying to find the cheaper price based on the ID and the expected output should be in the following format
ID Price Cheap
123 £12.99 Cheaper
123 £13.00
123 £12.99 Cheaper
456 £21.99
456 £20.90 Cheaper
789 £18.99
789 £16.99 Cheaper
I'd like to know how to implement this in excel/googlesheets?
You can use a MIN IF array function in Excel for this. The formula I entered in C2 is:
=IF(B2=MIN(IF(A$2:A$8=A2,B$2:B$8,"")),"Cheaper","")
Note that because it's an array formula, it must be committed with CTRL + SHIFT + ENTER.
For the following setup
Formula in C2 is
=ArrayFormula(IF(B2=MIN(IF(A2=$A$2:$A$8,$B$2:$B$8)),"Cheaper",""))
No need for nasty array formulas here:
=IF($B2=MINIFS($B$2:$B$8,$A$2:$A$8,$A2),"Cheaper","")

Excel combining countifs and left function

I have a list that I'm checking against the main data.
The main data looks like:
1234 1
1235 1
1234 1
1213 2
1231 2
1212 2
1231 3
1231 3
etc
The list I'm checking against the main data is:
1
2
3
etc
For each number in my list, I want to count how many start with 123, so the output looks like:
ID 123
1 3
2 1
3 2
etc
I have each ID in the list already. To drag down for each number, I currently have countifs(a1:a8, a1,b1:b8, "123") and it's obviously producing an error. I know I need to include left somewhere in here but I'm not sure where or how to. Much thanks.
In the Main Data sheet, add a column and enter formula as eg: C1=IF(LEFT(A1,3)="123",1,0). Drag the formula for every C cell. Then use that C cell in your SUMIFS in your list sheet eg: =SUMIFS(C:C,B:B,"="&E1) E col for me is your list.
Please refer screenshots below.
Identify begins with 123
sumifs to get the output
Edit:
Another Solution: =SUMPRODUCT(--(LEFT(Maindata!$A$1:$A$8,3)="123")*(Maindata!$B$1:$B$8=Maindata!D1)). This solution works fine to me.
sumproduct with --left
You can use someproduct to do this:
=sumproduct((Maindata!$A$1:$A$8=A1)*(left(Maindata!$B$1:$B$8)="123"))
Where A1 holds the digit you're determining the amount of "values that start with 123" for, and the main data is in worksheet Maindata, range A1:B8.
Is your data in the form of text or number values? If the former, your criteria should instead be "123*" (using an asterisk for wildcard), if the latter you might be able to get away with using ">1230".

Resources