How to split text after checking length in Google Sheets? - excel

How do I split contents of a cell if the cell is not empty in Google spread sheet?
Name | DOB | Day | Month | Year
------------------------------------------
John | 01/01/1995 | 1 | 1 | 1995
Doe | | | |
Dane | 10/05/1988 | 10 | 5 | 1988
Since Doe doesn't have a date of birth, the value for day, month and year is empty.
I am currently using
=ArrayFormula(SPLIT(B1,"/"))
How to check the condition before splitting?

Posting the answer as it worked for you,
=IF(B1="","",arrayformula)

There seems no need to make any special provision for blanks (nor need for any formula). Copy the DOB column (excluding header) under Day and apply Data > Split text into columns... with Custom Separator of /.

Related

Excel formul to count Table Range using month from date text

I have an excel workbook where I am trying to count the number of apples in a named table. The workbook has multle sheets each named Jan, Feb, Mar, etc. with a corresponding table range of the same name.
My main worksheet has a list of months as columns and fruit as rows, I want to use a countif or suitable function to count the number of each fruit per month using the column heading as the worksheet portion of the formula.
This is what I have tried, this works, but has to be manually coded for each month, i would prefer it be more dynamic.
=COUNTIF(JAN[Labels],$A2)
Note: A2 contains the word apple
I have tried to get the month from the column date but it doesnt work
=COUNTIF(TEXT(E25,"mmm")[Labels],$A2)
This is roughly what the "master" table should look like (for clarity)
| | Jan-20 | Feb-20 | Mar-20 | .... |
| Apple | 4 | 3 | 5 | ... |
| Pear | 5 | 4 | 9 | ... |
EDIT:
Just to assist with anyone trying to help, this is roughly what a table on another sheet will look like:
| invoice | labels|
| 12535 | Apple |
| 12536 | Pear |
| 12537 | Apple |
This table would be a named table of Jan or Feb, etc.
Please try this:-
=COUNTIF(INDIRECT(TEXT(G2,"mmm")),"A")
G2 contains a proper date.
Here is a variation of the above where column 2 of the table is specified as the range to count in.
=COUNTIF(INDEX(INDIRECT(TEXT(G2,"mmm")),0,2),"B")
If you must use column captions to identify the column I would suggest MATCH to find it.
OK, so I found an answer, combining the above answer by Variatus with an additional new row.
| A | B | C | D |
1| | Jan-20 | Feb-20 | Mar-20 |
2| |JAN[Labels]|FEB[Labels]|MAR[Labels]| <- =UPPER(TEXT(B1,"MMM"))&"[Labels]"
3|Apple | 5 | 7 | 3 | <- =COUNTIF(INDIRECT(B$2),$A3)
4|Pear | 7 | 2 | 9 |
5|Orange| 1 | 3 | 3 |
So formula in B2 makes an uppercase text value of the month from B1 plus the column name Labels.
The formula in B3 (and down) counts the number of instances of the fruit from the named table & column shown in B2.

Calculating Time Between Time/Days In Excel

I am having some difficulty finding the optimal solution to a problem I am having with Excel. Right now, I have a large sheet which has time on one axis (column A is every date between 1/1/2018 to 1/1/2019), and in the sheet I have time using the h:mm:ss function in different cells on different intervals.
For example, for rows 1/1/2018 - 1/3/18, there is a starting time on 1/1/2018 (example, 8:00:00), and then an ending time on 1/3/18 (example, 16:00:00).
The time between those two dates and two times on those dates is what I am looking to calculate.
This is on a sheet with 2000+ rows, and each interval is different (some may be three days, some may be the same day). The difference between all of these is another column with location. This looks like:
Row 2) Date, Location [A], Arrival Time (8:00:00), Departure Time (blank)
Row 3) Date (the next day), Location [A] (the same as above), Arrival time (blank), Departure Time (16:00:00)
+---+----------+----------+---------+-----------+
| | A | B | C | D |
+---+----------+----------+---------+-----------+
| 1 | Date | Location | Arrival | Departure |
| 2 | 1/1/2018 | A | 8:00 | |
| 3 | 1/2/2018 | A | | 16:00 |
| 4 | 1/3/2018 | B | 8:00 | 16:00 |
| 5 | 1/4/2018 | C | 5:00 | 13:00 |
| 6 | 1/5/2018 | C | 5:00 | 10:00 |
+---+----------+----------+---------+-----------+
I need to calculate the time spend in Location [A] between Arrival time on one date to the Departure time on the next date.
Please let me know what you think the optimal solution is to this problem, I am open to anything!
+--------+----------+---------+-----------+------------------------+
| Date | Location | Arrival | Departure | Time Spent in Location |
| 1/1/18 | A | 8:00:00 | 16:00:00 | 8:00:00 |
| 1/2/18 | B | 8:00:00 | | |
| 1/3/18 | B | | 18:00:00 | 34:00:00 |
| 1/4/18 | C | 8:00:00 | | |
| 1/5/18 | C | | | |
| 1/6/18 | C | | 16:00:00 | 56:00:00 |
+--------+----------+---------+-----------+------------------------+
The post from above is dead accurate - The trouble I am having is from the time intervals for each location being different (and random). I am trying to simply have an additional column which calculates the time spent in each location - from there I will be collecting data on each location and how many hours will be spent there.
Also, a big THANK YOU for the help so far! I am shocked by how quickly comments were made - sorry for the time it took me to make the mock-up, hope it helps make my goal in this more clear.
Actual Snip from sheet
One possible solution is to use the following formula in E2 and copy down.
=IF(C3="",((A3+D3)-(A2+C2)),IF(D3<>"",D3-C3,""))
EDIT: D4-C4 changed to D3-C3 in formula above)
It works by combining the date to the time, doing a math operation as needed and then stripping it out. Tap in a couple of IF statements to deal with rows that are single line locations, or the arrival only. It also assumes the first entry cannot be a departure.
Credit to urdearboy for the correct custom formatting. You will need to format the cells of the column to be [h]:mm
OPTION 2
This assumes that locations can be repeated. The use of a helper column is used to create a unique combination.
In F2, use the following formula and copy down as required:
=COUNTIFS($B$2:B2,B2,$C$2:C2,"<>"&"")
The $ locking the cells is very important. Note how it creates an expanding range as you copy down.
now technically speaking you can combine the following into one monster formula, but it will be difficult to follow and therefore maintain if someone else has to deal with it or you come back to it at a much later date. So on that note I will break it into 2 more helper columns and formulas
In column G we will identify the first row where a unique location occurs. A unique location is created by compounding the location name and the unique ID number which is a count of how often it has occurred in the list so far. Ie. A1 is the first time there was an arrival at location A, E2 is the second arrival at location 2. In G2 place the following formula and copy down.
=AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)
Now that the arrival row is identified the same needs to be done for the departure row. The same formula can be used but change the 15 to a 14. In H2 place the following formula:
=AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)
Now that you have those locations identified, you can use the following formula to calculate time:
=IF(D2="","",(INDEX(A:A,H2)+INDEX(D:D,H2))-(INDEX(A:A,G2)+INDEX(C:C,G2)))
In the example, I placed it in I2 and then I copied F2:I2 down as required. but it could be placed in E2 and copied down just as easily.
If you do not want those additional helper columns in G and H, then you can substitute them into your formula for time and it will look like this:
=IF(D2="","",(INDEX(A:A,AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))+INDEX(D:D,AGGREGATE(14,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1)))-(INDEX(A:A,AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))+INDEX(C:C,AGGREGATE(15,6,ROW($A$2:$A$16)/(B2&F2=$B$2:$B$16&$F$2:$F$16),1))))
A tidied up version using the monster formula and therefore not needing column G and H formulas:
Remember to apply custom formatting to your time calculation column of [h]:mm

How to find duplicate adjacent cells in Excel

I have 2 columns in Excel (like below) and I would like to identify (conditionally format) any rows that are exactly the same.
As you can see 326.001 1,000 HOUR are identical for the first 3 rows, I would like to highlight or mark these rows so I can see that they are not unique.
+---------+------------+
| ID | INTERVAL |
+---------+------------+
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 1,000 HOUR |
| 326.001 | 3,000 HOUR |
| 326.002 | 1 MONTH |
| 326.002 | 1 YEAR |
| 326.002 | 5 YEAR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 500 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 1,000 HOUR |
| 326.002 | 3,000 HOUR |
| 326.009 | 3 MONTH |
| 326.009 | 1 YEAR |
| 326.01 | 3 MONTH |
+---------+------------+
I would add a third column: EqualityTest, with a formula such as:
=AND([#ID]=A5,[#INTERVAL]=B5)
This assumes the data is sorted.
The above formula is for row 5, with ID and Interval in columns A and B. Copy-Paste the formula down, and apply conditional formatting to highlight False for unique values.
qroberts,
I'm not clear on your question.
If you're actually attempting to remove duplicate rows, Excel offers that as a function on the basic ribbon bar for the "Data" ribbon: the button (!) is "Remove Duplicates" in the "Data Tools" section on the "Data" ribbon.
If, instead, you are looking for a highlighter which will identify duplicates, things are a bit more complicated, as you need a macro which will find duplicates and then turn on some form of formatting/highlighting (I suggest formatting a background color).
For a macro which will highlight duplicates, we need to hear a bit more to understand your needs. If you have two different sets of duplicates, do you want them highlighted to different colors? If the number of duplicate sets
gets large, this could be a problem.
As another poster has noted, it also matters whether your candidate set is sorted. A full range search for duplicates would be an interesting bit of coding.
So use COUNTIFS():
=COUNTIFS($A$2:$A$10000,$A2,$B$2:$B$10000,$B2)>0
It will return true for any that has duplicates in both columns. This formula does not care if the data is sorted or not.

Moving range/array reference in Excel table

Friends, I'm hoping you can help. I'm fairly certain I found a solution to this problem below a while ago, but silly me didn't write it down and now I can't remember how I did it. I'm drawing a blank on what to search for (Google is flooded with answers on "dynamic named ranges", which is not what I'm aiming for here). So, the question:
How can I define a range within a formula (say, RANK for example) that moves as I progress down through a table? I'm trying to avoid using INDIRECT, because it becomes a bit of a memory/processor hog when repeated throughout a large table. Pretty sure there is another way, maybe with INDEX or MATCH?
A simplified version of the data would appear as follows:
Column A has a bunch of reference numbers, each one repeats a few times.
Column B has a bunch of timestamps
Column C is where I would like to rank the timestamp in column B, as compared to all other timestamps that share the same reference number in column A.
The result set should look like this:
| A | B | C |
| abc123 | 01/01/2014 12:30 | 1 |
| abc123 | 01/02/2014 12:30 | 2 |
| abc123 | 01/02/2014 13:30 | 3 |
| abc123 | 01/03/2014 09:30 | 4 |
| def456 | 01/01/2014 12:30 | 1 |
| def456 | 01/01/2014 12:45 | 2 |
| xyz987 | 01/02/2014 12:30 | 1 |
| xyz987 | 01/02/2014 16:30 | 2 |
| xyz987 | 01/03/2014 11:30 | 3 |
Any ideas on what would be the least taxing solution for the processor in this case?
So here is the trick:
copy and paste in C1 and drag and fill down till end.
=IF(A2=A1;SUMPRODUCT(--(A$1:A$9=A1);--(B1>B$1:B$9))+1;SUMPRODUCT(--(A$1:A$9=A1);--(B1>B$1:B$9))+1)
this is an array formula, so press ctrl+shift+enter to calculate the formula
Here is the example sheet in this file downloadable from this link
P.S. remember to adjust the formula to your regional settings by replacing the ";" with "," . Have fun.

excel merge rows based on column values

So I've been searching for the information I need and have not really been able to find a simple solution, though it seems like there should be one. Basically, I have the following
John | Doe | 123 Wallaby Ln | 00123 | | |
John | Doe | | 00123 | xxx | yy |
Jane | Doe | | 01234 | | zz |
Jane | Doe | bleep blop ln | | xx | |
And I need
John | Doe | 123 Wallaby Ln | 00123 | xxx| yy |
Jane | Doe | bleep blop ln | 01234 | xx | zz |
Basically pretty simple, I need to merge cells with the same Column 1 & Column 2 data to get as comprehensive and concise a list of data. You'd think this would be readily available through google as a simple formula but I have only found VBA solutions (I have never used VBA before, or macros for that matter so I'm not sure how to use them or fix errors in them). Any help is greatly appreciated.
Thanks in advance!
The easiest option is to merge the content of A & B in one column ( insert a new column in C)
C1 =A1&" "&B1
Roll down the formula
Sort per column C
Make sure you have descriptive name on row 1 to describe your column.
Select the complete table
Create a pivot table, drop the C column in the row section to obtain the list of unique name.
Copy the list of unique names in a new sheet
and then look at vlookupall describe here excel vlookup with multiple results to create your own function.

Resources