This is a follow up to the earlier question.
The only differences between the original formula & the one that is causing a problem is location AC3 is a static date & location S2 is dynamic. S2 houses a dynamic formula that allows for a leap year:
=DATE(YEAR(Q3)+1,MONTH(Q3),DAY(Q3-1))
Location Q3 refers to a basic date formula:
=TODAY()
I hope this helpful.
Change your formula in S9 to:
=Date(year(s2),1,S8)
The reason for this is Date is looking for 3 integers to be passed to it. What you did was pass it a date in the place of a year number that really did not make sense to excel. What you needed to send is:
=Date(2016,1,22)
What you sent was:
=Date(5/5/2016,1,22)
or more accurately
=Date(42496,1,22)
42496 is how excel stores a date. What the year function does is strip the year part of the date and return it as an integer.
=Year(5/6/2016)
this really equates to
2016 'an integer
Hope that clarifies some things.
When you have all your formulas condensed down to a single cell and pointed at one year, consider arranging them as follows:
or
You should only need row 3 or row 4, which ever you prefer. Also once you have one column of holidays set up, you should just be able to copy them to the right.
Related
I have a excel spreadsheet with two columns. One with a date and another with the value.
I want to get the working day of the month with the lowest value.
I tried to use a pivot table for it and then group the date but I get a lot of errors.
You can find the spreadsheet here and the sheet name is Historical. The others are just attempts made by me.
Spreadsheet
Thanks
The formula entered in E2 below
is
=AGGREGATE(15,6,(POWER(10,LOG10(((YEAR(D2)=YEAR($A$2:$A$3254))*(MONTH(D2)=MONTH($A$2:$A$3254)))))*$B$2:$B$3254),1)
and the array formula entered in F2 below is
=INDEX($A$2:$A$3254,MATCH(YEAR(D2)&MONTH(D2)&E2,YEAR($A$2:$A$3254)&MONTH($A$2:$A$3254)&$B$2:$B$3254,0))
I suggest to make an triple nested if-construct that checks if the weekday of the date is a workday, or the date+ 1 or the day +2. Assuming the date is in cell A4
= if(instr(weekday(A4),”23456”)>0, A4,
if(instr(weekday(A4+1),”23456”)>0, A4 + 1,
if(instr(weekday(A4+2),”23456”)>0, A4 + 2,”cannot happen”)))
Explanation: one of 3 consecutive days is always a working day.
There may be typos since I edit that on iPad without Excel available to test.
Weekday returns 1 for Sunday and 7 for Saturday. So 2-6 are workdays.
However with that simple approach you will not detect public holidays on a working day if that is a problem.
Hope I understood you question correctly. One data example with solution would have explained it better.
So, I have a range of monthly dates that span several years. Then I have a dollar value in the next cell lets call it A1:B100. I want to find the cell in B that corresponds with today's date. What I've used that works in finding the correct date is: AND(MONTH(a1)=MONTH(TODAY()),YEAR(a1)=YEAR(TODAY())) I just need to put it in a lookup function that spans the date range, but I'm stumped
Any help would be great.
These functions look for the value in b that matches today's date and then pull in the value from a. xlookup has an easier syntax, but you may need index/match if you don't have the newest version of excel.
=INDEX(A1:A5,MATCH(TODAY(),B1:B5,0))
=XLOOKUP(TODAY(),B1:B5,A1:A5)
Edit: I re-read your post, and if your data in a is by month (ie 1/1/2021, 2/1/201), just make sure it is in order, and change the match type to less than. If your data is in a different format, please post a screenshot of your data.
=INDEX(A1:A8,MATCH(TODAY(),B1:B8,1))
=XLOOKUP(TODAY(),B1:B8,A1:A8,,-1)
I'm trying to put multiple rows which contain a date of the month between the first and last day of the month and I want to put them togeather as the first of the month dpeending on which month they are in:
for example; if they have the month of 12 i want to make them the 01/12/2020 if it was november 01/11/2020 and so on...
What i am looking for is to get three or more dates into a single one:
Date
03/12/2020
16/12/2020
27/12/2020
And make it:
Date
01/12/2020
Thanks for any help on how i could go about this, im struggling to find a solution
(I have tried text join and concatenate and neither work)
If you have Excel365 then use-
=DATE(2020,UNIQUE(MONTH(A1:A4)),1)
If you have dates with different years then try below formula.
=DATEVALUE("01-"&UNIQUE(TEXT(A1:A4,"mm-yyyy")))
Pretty unconventional way of doing it but works:
=EOMONTH(EDATE(AVERAGE(A1:A12),-1),0)+1
Where A1:A12 is a range of dates.
You have not specified well whether your dates are strings or actual Excel dates. Nor is it clear to me whether this is an example of a single cell in a larger row. The solution would be different based on the answer to these questions (which I do not have enough reputation to put as comments).
If you already have these values as dates put a new value in an adjacent column. Assuming the existing date value is in cell A1:
=DATE(YEAR(A1), MONTH(A1), 1)
However, if the date value is actually a string you will need to hard code the extraction of the values. Assuming, the are in fixed length strings as your image shows, with dd/mm/yyyy format:
=DATE(RIGHT(A1, 4), MID(A1, 4, 2), 1)
I have a cell G4 with date and time in a format (Text string):
1/29/2020 1:34:24 PM
I need to convert it to DATE formatted cell. How to do that?
I have tried to get numbers and convert them to DATE with this formula:
=DATE((MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2));(MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1));(LEFT(G4;FIND("/";G4;1)-1)))
So:
I am extracting year:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
Month
=MID(G4;SEARCH("/";G4)+1;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)-1)
Day
=LEFT(G4;FIND("/";G4;1)-1)
I am getting as a result:
1.5.2022
I need it as it is now, but output should be 29.1.2020 in this case. Later I want to get day difference two that way formatted dates. Is it possible to do it with formula without performing any other cell formatting operations?
EDIT:
I got it working, the only problem is:
How to extract number (year) after third "/"? My current formula is not correct:
=MID(G4;SEARCH("/";G4)+4;SEARCH("/";G4;SEARCH("/";G4)+1)-SEARCH("/";G4)+2)
It does not function correct in this case:
2/5/2020 12:21:05 PM
EDIT:
I did it this way (I also had to minus G2 - F2, to get days difference):
=IFERROR(DAYS(MID(G2;SEARCH("/";G2)+1;SEARCH("/";G2;SEARCH("/";G2)+1)-SEARCH("/";G2)-1)&"."&LEFT(G2;FIND("/";G2;1)-1)&"."&MID(G2;FIND("/";G2;FIND("/";G2)+1)+1;4);MID(F2;SEARCH("/";F2)+1;SEARCH("/";F2;SEARCH("/";F2)+1)-SEARCH("/";F2)-1)&"."&LEFT(F2;FIND("/";F2;1)-1)&"."&MID(F2;FIND("/";F2;FIND("/";F2)+1)+1;4));"")
You probably need to replace an order of day.month.year and "." to "/" if you are using different date setting (region). I have one setup, so this seems to work.
FYI DATES in excel are stored as integers. They represent the number of days since 1900/01/01 with that date being 1. TIME is stored as a decimal representing fractions of a day or 24 hours. 0.5 represents noon. 24:00 is not an officially supported time in excel, but will work with some functions.
The DATE Formula is looking for three arguments representing YEAR, MONTH, DAY in that order.
DATE(Year, Month, Day)
You need to pull the text from your string representing these values. I find it easiest to pull each one individually in its own cell to ensure the part of the formula is working first then copy and past that part into the DATE formula so the whole calculation in the end can be performed in one cell.
YEAR
To get the year use the following formula:
MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4)
MONTH
To get the month use the following formula:
LEFT(G4,FIND("/",G4)-1)
DAY
To get the day use the following formula:
MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)
COMBINED FORMULA
Place the above formulas into the date formula as follows:
=DATE(MID(G4,FIND("/",G4,FIND("/",G4)+1)+1,4),LEFT(G4,FIND("/",G4)-1),MID(G4,FIND("/",G4)+1,FIND("/",G4,FIND("/",G4)+1)-FIND("/",G4)-1))
Note the only cell reference in the formula is G4. The results of the formula are not in an Excel Date format. Change the formatting of your cell to meet your needs. In your case I would apply a custom cell format of d.m.yyyy
If you have TEXTJOIN,
=TEXTJOIN("/",TRUE,INDEX(FILTERXML("<a>,<b>"&SUBSTITUTE(SUBSTITUTE(TEXT(A1,"dd/mm/yyyy hh:mm:ss"),"/","</b><b>")," ","</b>",1)&"</a>","//b"),N(IF({1},{2,1,3}))))
Depending on your version it may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.
the reason the second did not work is that Excel actually changed it to a date and a date is a double, not text. So there are no / in the data. so we need to force back to the incorrect string.
Those for whom the TEXTJOIN function is not available can use this:
=DATE(FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[3]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[1]");FILTERXML("<DATA><A>" & SUBSTITUTE(SUBSTITUTE(A1;"/";"</A><A>");" ";"</A><A>") & "</A></DATA>";"/DATA/A[2]"))
I have two columns of year in excel sheet as year.months format (column first as 1.11 means 1 year 11 months) column second as 0.7 means 7 months). I need difference between two columns as year.months format. i.e., 1.11-0.7=1.4 means 1 year 4 months.
This approach will perform the math by converting everything to the same base units as month. You can perform the steps over multiple column which will make it easier to read, maintain and troubleshoot. When everything is working you can combine it into a single formula which will be a monstrosity that is hard to read and potentially maintain by others in the future.
For the sake of this solution, assume your 1.11 date is in A1 and you 0.7 date is in B1.
Step 1) Convert A1 and B1 to months
In C1 place the following formula and copy it to D1
=LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1))
Step 2) Find the difference in months
In E1 Place the following formula
=C1-D1
Step 3) Convert difference in months back in to year.month format
In F1 place the following formula
=INT(E1/12)&"."&(E1-INT(E1/12)*12)
Now if you got and substitute formulas into one another so its all in a single cell, your formula will wind up looking the following.
=INT(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))/12)&"."&(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))-INT(((LEFT(A1,FIND(".",A1)-1)*12+RIGHT(A1,LEN(A1)-FIND(".",A1)))-(LEFT(B1,FIND(".",B1)-1)*12+RIGHT(B1,LEN(B1)-FIND(".",B1))))/12)*12)
I would not want to be someone new coming in and looking at that and trying to figure out what its doing let alone editing it 3 months down the road when a change is required.
A few caveats, Make sure the date in A is bigger than the date in B. It gives bad results for negative values. Also ensure there is always a "." in the date or errors will ensue. If there is a 12 month difference it will currently display 1.0 as the difference instead of 0.12. If the later is required, a special case would need to be developed for when there is differences resulting in multiples of 12 differences.
Working with DatedIF
Assume start date is in B1 and end date is in A1.
Step 1) Convert date
Convert the string to an actual excel serial date
In C1 and Use the following formula and copy to D1
=DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1)
The conversion assumes the first of the month
Step 2) Determine the difference in months
Place the following in E1
=DATEDIF(D1,C1,"M")
Note the start date need to be further back in time than the end date or you will get #NUM error.
Step 3) Convert back to your string format for y.m
Place the following in F1
=INT(E1/12)&"."&(E1-INT(E1/12)*12)
and combined into the uglyness of a single cell formula:
=INT((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))/12)&"."&((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))-INT((DATEDIF(DATE(LEFT(B1,FIND(".",B1)-1),RIGHT(B1,LEN(B1)-FIND(".",B1)),1),DATE(LEFT(A1,FIND(".",A1)-1),RIGHT(A1,LEN(A1)-FIND(".",A1)),1),"M"))/12)*12)
Let's say A1=1.11 and B1=0.7 then formula would be:
=LEFT(A1;FIND(".";A1;1)-1)-LEFT(B1;FIND(".";B1;1)-1)&"."&(MID(A1;FIND(".";A1;1)+1;2)-MID(B1;FIND(".";B1;1)+1;2))