Removing duplicate values for order sequence numbers - google-sheets

Hi guys a Simple question.
I got 3 columns
A, B, C
with Name , Sku , order no .
Example :
Daniel, 45785 , C2=if(A2>0, CONCATENATE("x",A2,TEXT(ROW(A1),"000")),"")
so "C2" combines the other two cells and give me an unique order number as "xDaniel001"
Now the problem is if Mr. Daniel enters 2-3 sku's, its will generate order number for each entry as "xDaniel002 " and so on.
So how can i Skip the order numbers if Daniel orders 2-3 In Column C
order number should be in sequence .
this is what the output should like
A , B , C
Daniel, 45785 , xDaniel001
Daniel , 54852 , ( formula return with no value )
Asha, 54824 , xAsha002
Craig , 24584 , XCraig003
Daniel , 89784, ( formula return with no value )
All suggestions are welcome :)
Thanks

Try in C2:
=ArrayFormula(IFERROR(IF(LEN(A2:A)*(MATCH(A2:A,A2:A,0)=(ROW(A2:A)-1)),"x"&A2:A&TEXT(MATCH(A2:A,UNIQUE(A2:A),0),"000"),)))
And with your qualification in comments, that a new ID must be produced on a new day:
=ArrayFormula(IF(LEN(A2:A)*(MMULT((ROW(A2:A)>TRANSPOSE(ROW(A2:A)))*(A2:A=TRANSPOSE(A2:A))*(B2:B=TRANSPOSE(B2:B)),SIGN(ROW(A2:A)))=0),"x"&B2:B&TEXT(MATCH(A2:A&CHAR(9)&B2:B,UNIQUE(A2:A&CHAR(9)&B2:B),0),"000"),))

Related

how to concat/merge two columns with different length?

I'm new to google sheet. I have a column(E) with the date and another with a session(F), I want to merge them into one column with each date & different session just like the first few rows in column C.
I've tried "=ArrayFormula(concat(D2:D,concat(" ",F2:F5)))" in column C but only got the first date.
use:
=INDEX(QUERY(FLATTEN(FILTER(E2:E, E2:E<>"")&" "&
TRANSPOSE(FILTER(F2:F, F2:F<>""))), "where not Col1 starts with ' '", ))
see: https://stackoverflow.com/a/68775825/5632629
In your cell C1, try this formula:
=ArrayFormula(E1:E&" "&F1:F)
Well you can simply do concatenate cells like this:
CONCATENATE(E1, " ", F1)
to get what you want I think.
What you're looking for is a cartesian product. I don't have a single formula that does the entire thing for you, but I can suggest a two-step approach.
Get the cartesian product with this formula:
=ARRAYFORMULA(SPLIT(FLATTEN(E2:E9 & "|" & TRANSPOSE(F2:F5)), "|"))
This gives a pair of each date against each time in two result columns. You can then concatenate each row of them in a final result column.

Lookup/Query confusion - Really stuck but I figure it's not as hard as I'm making it

So, I have an imported sheet with colums like so...
Name
SAT1045
SAT1200
Dave
0
1
Angela
0
1
Stuart
1
0
From this I need to generate attendance lists displaying the times (SAT1045) followed by those attending. Those attending have a 1 in that column. So as a example:
SAT1045
Stuart
SAT1200
Dave
Angela
The other trick is there are multiple days and times, so I have used Data Validation to populate a dropdown on a fresh sheet. So the chosen date would populate the list below it.
I just don't know what Query or Lookup function to use to strip the data from the import as there is also a lot of nonsene data in the import between the Names and the dates.
Can anyone help?
I have tried numerous levels of Query's and Lookups but my head just can't get around this one
I would recommend you to use a second sheet for the attendance.
If the Name cell in your exemple is A1, you cvan have someting like this in your second sheet:
In A1 (second sheet) :
=Sheet1!B1
this will set the header at the corresponding time
In A2 (second sheet) :
=QUERY(
Sheet2!$A$1:$C$4,
CONCATENATE("select A where ",SUBSTITUTE(ADDRESS(1,COLUMN(B2),4),1,""),"=1")
,0
)
this will get the names for the time set in the first row.
Than tou only hace to drag those to for every attendance to get.
Edited to adjust to OP's comment
=QUERY(
[table of time and 0/1],
CONCATENATE(
"select A where ",
SUBSTITUTE(
ADDRESS(
1,
COLUMN(
INDEX(
[Row with all times],
match(
[Reference of the cell with the dropdown],
[Row with all times],
0
)
)
),
4
),
1,
""
),
"=1"
),
0
)
this formula here allow you to get the attendants based of the time in the cell above it.
So, from the left to the right :
match here will look through the different time based on the selected one in the cell above, and will return the reference of the cell;
The whole part Substitute(Adress(Column(Index()))) will return the letter of the column in wich the selected tim is. this allow to have a valid Query as it requiress the letter of the column to work;
And finally the Query returns every name where the value is 1 in the column corresponding to the chosen time
The values of [Row with all times] should always be the same. In your case, either 1:1 or $AC$1:$AP$1. In the first case it's just that if you add a row for a new time it'll take it into acount

How to write a query that filters on multiple conditions?

I'm trying to get the product and amount info for Alex (as in attached). However, if Alex has got any product with the amount showing as zero shouldn't be picked up.
What query or formula should I go with on g-sheets?
You can use FILTER function with 2 conditions
Speaking english:
Show column with products and numbers
Column with numbers is not 0
Column with names is Alex
=filter(C2:D,B2:B=F2,D2:D<>0)
You can also do it using QUERY formula:
=query(B2:D,"select C,D where B = '"&F2&"' and D <> 0")
F2 is a cell where you put name

Using SEARCH function to count occurrence of multiple values

So I've Two lists in Google sheets. one is a (relatively short) list of names, let's say a rooster of employees. The second list is (rather a long) list of shifts, which notes the employees who were present.
for example:
List A - (rooster):
___________________
Mike
Linda
Carrie
Dave
List B - (Import_shift_data):
____________________________
Mike, John
Dave, Linda, Mike
Carrie
Dave, John
Linda
Mike
Dave, Carrie, John, Mike
My goal is to count the presence of each employee.
Now, here are the tricky parts:
List B updates every day, and each cell contains more than one name.
List A also updates, as some employees join the team and other leave.
Each shift could by a day shift, or a night shift (listed in another column next to List B) and I need to count them separately.
The Day/night column is in a parallel column next to shift column, and has one of two values, "Day" or "Night"
So my notion was to create an array formula, who can expand or shrink based on the number of values in List A. The problems is, I Can't yield and results from using the whole {list A} as the first argument in the SEARCH function.
I've tried the foloowing:
=Arrayformula(IF(INDIRECT("A2"):INDIRECT(CONCATENATE("A",MAX(Arrayformula(IF(isblank($A:$A),"",Row($A:$A)))))) = 0,"",COUNTIFs('Import_shift_data'!$P:$P,INDIRECT("A2"):INDIRECT(CONCATENATE("A",MAX(Arrayformula(IF(isblank($A:$A),"",Row($A:$A)))))),'Import_shift_data'!$M:$M,"Night")))
.
But this formula only works for a shift with a single employee.
I also wrote this one:
=Countifs(Arrayformula(ISNUMBER(SEARCH(A2,'Import_shift_data'!$P:$P))),"true",'Import_shift_data'!$M:$M,"Night")
which works fine, but I need to manually drag it up or down every time List A (The rooster) is updated.
So my end game is to have two arrays, one that counts night shifts for each employee, and one who counts day shifts. those arrays should automatically shrink or expand by the size of the rooster. (List A)
Note: If relevant, I may also note that the names in {List A} may contain more than one word, in case there are two employees with the same first name.
A copy of the spreadsheet:
https://drive.google.com/open?id=1HRDAy9-T_rflFpzanZq0fmHpV0jTZg6Rc4vHyOu-1HI
day shift:
=ARRAYFORMULA(QUERY(TRIM(TRANSPOSE(SPLIT(TEXTJOIN(", ", 1, B2:B), ","))),
"select Col1,count(Col1) group by Col1 label count(Col1)''", 0))
night shift:
=ARRAYFORMULA(QUERY(TRIM(TRANSPOSE(SPLIT(TEXTJOIN(", ", 1, C2:C), ","))),
"select Col1,count(Col1) group by Col1 label count(Col1)''", 0))
I Think I've found the Solution, I've used player0's idea of rearranging the data vector and split non-single shifts into single cells.
so basically it goes:
=Arrayformula(CountiF(Transpose(SPlit(Textjoin(" , ",TRUE,QUERY('Import_shift_data'!A:P, "select P where M = 'Night' ", 1))," , ",False)),INDIRECT("A2"):INDIRECT(CONCATENATE("A",MAX(Arrayformula(IF(isblank($A:$A),"",Row($A:$A))))))))
Thanks player0 !

Combine multiple Query select and where conditions google spreadsheets

Not sure how to title this one... So please forgive me.
What we have is a POS sheet, I import POS data from Distributors then given the zipcode value it sorts the info and populates other sheets within the doc for each person responsible for the sale.
Sheet2 is the main POS sheet where all the data is imported into.
Rep Template is the sheet for any given rep responsible for the sale.
The Rep Template contains again a list similar to Sheet2 but only sales that apply to them (thanks to the zip code formula Im using). I However have on problem in this Rep Template. Im using a QUERY eg
=query(index(A19:F); "select (month(Col1)+1),sum(Col4), (sum(Col4)*.05) where Col1 is not null group by (month(Col1)+1) label (month(Col1)+1) 'MONTH',sum(Col4) 'TOTAL SALES',(sum(Col4)*.05) 'COMMISSION EARNINGS' ")
***See the highlighted yellow section #L9
This works fine
Q.What I would like to do is add this to it
but I cannot use (sum(D)*.05) again for another column...
=query(A19:F, "select (sum(D)*.05) where F != 'N' group by (month(A)+1) label (sum(D)*.05) 'ADJUSTED COMMISSION EARNINGS' ")
***see the highlighted orange section #N3
(Also why is this skipping down one cell that could solve a lot)
The thing is some commission for reasons xyz may be omitted once verified (hence F19:F) an "N" in COLUMN F will omit that line from the commissions resulting in adjusted commissions earnings.
Here is my Spreadsheet
https://docs.google.com/spreadsheet/ccc?key=0AqZjzFwBse-sdGZ4M3ppWVBuNTdJV3dYbGlwb0NUeVE&usp=sharing
Thanks everyone ; )
Please change Col1=A and Col4=D, it is right
use double-query:
=QUERY(QUERY(A19:F,
"select sum(D)
where F != 'N'
group by month(A)+1
label sum(D)''", ),
"select Col1*.05
label Col1*.05'ADJUSTED COMMISSION EARNINGS'")

Resources