Excel difference between dates not working - excel

I have the following data in columns:
A B
1 1/08/2021 29/11/2021
These values are the result of some searches from other columns with this formula:
=MINIFS('sheet2'!$G:$G,'sheet2'!$F:$F,$E1)
Both the source cells and the resulting cells are of type date
I then look to get the DATEDIF between these and I end up with #NAME?
=DATEDIF($A1,$B1,”M”) /* Corrected the above "W" to "M"... typo! */
I tried DATEVALUE on the search result cells like this:
=DATEDIF(DATEVALUE($A1),DATEVALUE($B1),”M”)
But I end up with #VALUE? so the resulting values from the searches are not seen as dates. What have I missed? Thanks!

The "W" on =DATEDIF($A1,$B1,”W”) is not a valid unit, accordingly to Microsoft's documentation (here).
The list of valid units is:
"Y" : The number of complete years in the period.
"M" : The number of complete months in the period.
"D" : The number of days in the period.
"MD": The difference between the days in start_date and
end_date. The months and years of the dates are ignored. Not
recommended, as there are known limitations with it.
"YM" : The difference between the months in start_date and end_date. The days
and years of the dates are ignored
"YD" : The difference between the
days of start_date and end_date. The years of the dates are ignored.

You have two mistakes:
The #NAME? error is because you are using left and right quotation marks instead of straight quotation marks. eg: “W” instead of "W".
If you correct that, you will see a #NUM! error because W is not a valid argument for the function.
See MS Help for the DATEDIF function for more information as well as a warning about the MD unit.

Related

Issue with DATEDIF function

DATEDIF function giving different values as shown in the snapshot.
Why this?
First of all, you should avoid passing D2 directly to DATEDIF formula.
DATEDIF requires first 2 arguments as a date. You pass 0 and D2 (C2-B2). Since lowest possible date in excel is 01-Jan-1900 and it is = 1, your arguments are 0 = 0-Jan-1900 (non existing date) and 546 = 29-Jun-1900. You would get more errors in calculation if your dates would include leap year (1900 is not leap year)
Also consider looking at Microsoft as it states there are issues with "md" argument (see "Known issues").
So correct formula would be:
=DATEDIF(B2,C2,"y")&" years "&DATEDIF(B2,C2,"ym")&" months "&DATEDIF(B2,C2,"md")&" days"
Result:

Create Date from MM/DD format and include current year? Power Query

I have a table that has a series of Columns with data I need to split out. Example below
STATUS#10/16 12:00:00 (CODE)
I've been able to split it easy enough and when I originally tried to set the date on an older dataset it identified it as a date e.g. 16th Oct 2021 However I started to get errors on this date column and trying with different datasets (10/12, 10/13, 10/14) it is not finding the date. I tried the following query code but I'm receiving errors
[STATUS DATE] is split to 10/14, 10/15 etc
#date( Date.Year(DateTime.LocalNow), Date.Month(Text.End([STATUS DATE]), 2), Date.Day(Text.Start([STATUS DATE]),2))
However I'm getting a function error so I tried
Date.From(Date.Day(Text.Start([STATUS DATE]),2) & Date.Month(Text.End([STATUS DATE]),2) & Date.Year(DateTime.LocalNow)
I have also tried to do this from an example column however the query created is looking at the cell value e.g. if 10/14 then 14/10/2021 else if 13/10 then 14/10/2021. This method i feel is prone for error once I include a larger dataset.
Is there anyway I can determine the date value based on mm/dd format? But with year end in mind, make the YYYY be determined by current year unless we move into Jan and then I don't want the Oct, Nov, Dec value showing as 2022.
You don't really show what your original data looks like.
But if it is like:
Source
Then you can use this code in the Add Custom Column dialog:
let
split=Text.SplitAny([STATUS DATE],"#/ "),
mnth = Number.From(split{1}),
dy = Number.From(split{2})
in
#date(Date.Year(DateTime.LocalNow()),mnth,dy)
The Text.SplitAny function lets you input a list of delimiters and the text will split on all of them. So it is relatively simple to extract the month and day values
to create:
Split [STATUS DATE] one more time into [Month] and [Day] column, using the "/" as a separator. Then you don't have to bother with 1 or 2 digit numbers and you can simply use this formula:
#date(Date.Year(DateTime.LocalNow()), [Month], [Day])
DateTime.LocalNow() is a function, so you need to add the brackets.
[Month] and [Day] are numbers already, so you don't need the Date.Month() or Date.Day() functions.

Formatting date in Excel

How can I easily format "202104" --> 2021/04 in Excel?
My current method is to concatenate the original string with "01" and then change it into a date. However, I am seeking a more efficient format method.
Thanks
Try this.
For Text
=LEFT(A1,4)&"/"&RIGHT(A1,2)
For Date Value
=TEXT(DATEVALUE(LEFT(A1,4)&"/"&RIGHT(A1,2)),"YYYY/MM")
As far as I know, 2021/04 is not a valid date in Excel, but 2021/04/01 (first of April, year 2021) is.
In order to achieve this, you can use this formula:
=DATE(INTEGER(202104 / 100);MOD(202104;100);1)
Where:
1) INTEGER(202104/100) is the integer division of 202104 by 100, calculating the year.
2) MOD(202104;100) means 202104 modulo 100, in order to calculate the month.
3) 1 means the first day of the month.

Excel split cost figure between months with partial dates

I have a list of cost figures with start dates and end dates which I need to split between months, I have searched for the solution to this problem but cannot seem to find one that will work with partial months i.e.( startdate:01/01/2015 enddate: 15/04/2015 cost:10000) which would leave figures like Jan:2857, Feb:2857, Mar:2857, Apr:1429.
I have been trying to modify this example: http://www.excel-university.com/excel-formula-to-allocate-an-amount-into-monthly-columns/ but having no luck getting the partial months working.
Any suggestions or help would be most welcome. Thanks in Advance
if you calculate it on daily basis, would it be ok? the result would be:
01.01.2015 01.02.2015 01.03.2015 15.04.2015
2.857,14 2.857,14 2.857,14 1.428,57
your daily amount is:
=10.000/(DAYS360(startdate;enddate;TRUE)+1)
(be carefull of true and false argument)
under the dates or instead of 2.857,14 etc. insert the formula:
=IF(DAY("your date")>1;DAY("your date");30) * daily amount
This formula assumes that you want to have 30 days in each month:
=IF(DAY(01.01.2015)>1;DAY(01.01.2015);30)
result = 30
=IF(DAY(15.04.2015)>1;DAY(15.04.2015);30)
result = 15
so if months begins with a date different from the 1st it will give you the number of days.
if you want to match months with your startdate and enddate (if i understood your comment correctly), you could do:
=IF(OR(
AND(MONTH(startdate)=MONTH(your date);YEAR(startdate)=YEAR(your date));
AND(MONTH(enddate)=MONTH(your date);YEAR(enddate)=YEAR(your date))
);"match";"no match")
by this you make sure that month and year correspond.
If you want to get the number of days in a month automatically, you could use:
=DAY(DATE(YEAR("your date");MONTH("your date")+1;1)-1)
but this does not assume anymore 30 days, you can change it with if statement
I hope this helps,
Best - AB

DATESYTD : Only constant date value is allowed as a year end date argument

I was trying to generate a YTD Report for sales with previous year comparison. We are following a Fiscal calendar. So it is necessity to use the second parameter of DATESYTD to pass the fiscal year end date.
But it seems like DATESYTD accepts only constant date as second parameter, like "12-01" or "06-01".
The problem here is we have a whole set of fiscal years with different end date, so when i try to pass a measure or do a switch case it is giving me the following error.
=CALCULATE (
SUM (Customers[quantity]),
DATESYTD (DimDate[Date], SWITCH([fiscal_year],
2007,"12-30",
2008,"12-28",
2009,"12-27",
2010,"12-26",
2011,"12-25",
2012,"12-30",
2013,"12-29",
2014,"12-28",
2015,"12-27"
)),
ALL (DimDate)
)
Only constant date value is allowed as a year end date argument.
The above mentioned fiscal year is used as a slicer, so i was thinking of passing the corresponding constant to the DATESYTD, but with no luck.
Is there any way to pass the values dynamically, i have heard about dynamic constant but have no idea about it. Any examples would be great.
Thanks in advance.
Try TOTALYTD.
TOTALYTD(,[,][,])
TotalYTD allows you to perform your summing, your date dimension, a filter, but also a FY ending date, which can either be a date you provide, or, a pointer to the date dimensions fiscal year column.
So for example:
=TOTALYTD(SUM([Customers[Quantity]),DimDate[Date],DimDate[FiscalYearEndDate])
The optional Fiscal Year end date has to be a constant.
If you attempt to point to DimDate[FiscalYearEndDate] you will receive the following error message:
Only constant date value is allowed as a year end date argument.
I have yet to find a solution for any of the YTD functions where the fiscal [YearEndDate] is end of February and any of the current or comparative years is a leap year.

Resources