I am trying to create a custom function of given a date in Filemaker, I would like it to determine if this week of fiscal year number is within the first week of quarter else it will calculate the first date next quarter. Our Fiscal year starts on July 1
So for defined requirements our FY starts on July 1 and Qtrs are on week # 1, 14, 27, 40 our weeks go from 1-52 and the week starts on Tuesday (Defined as day 3). If FY starts on Monday than the first week will be from Mon-Tues (Therefore a shortweek) then week 2 will be a full 7 day week.
Example---> If I have a date 09/09/2011 that would be week 11 in Q1, therefore since it is not the first week of the quarter I would like the following date for the next Qtr which would be Wk 14 first date of 9/27/2011. So my evaluation needs to determine whether the given date is within the first week of a qtr (weeks 1, 14, 27, 40) or provide the first week of the next qtr.
Also here is the initial CF I was working with from Brian Dunnings site.
https://www.briandunning.com/cf/147
I know this would be developed in filemaker but there maybe something developed in another language which may apply...
Thanks in advance
Try this as your starting point:
Let ( [
startFY = Date ( 7 ; 1 ; Year ( Datefield ) - ( Month ( Datefield ) < 7 ) ) ;
firstTuesday = startFY - Mod ( startFY - 2 ; 7 ) ;
fiscalWeek = Div ( Datefield - firstTuesday ; 7 ) ; //numbering starts at 0
targetWeek = 13 * Ceiling ( fiscalWeek / 13 )
] ;
firstTuesday + 7 * targetWeek
)
Note that the result is always a Tuesday; you may want to adjust this for the boundary cases of fiscal year start and end. The way it works now, you'll get a result of July 30, 2015 for both June 15, 2015 and July 6, 2015.
Related
I'm trying to find out the weekday i.e Mon, Tue, Wed etc. from a date-range formatted as yyyy mm dd
I tried to use the formula format(day(Date Table),"ddd"), but the weekday is wrong. In my example, the output of 2020.01.01 gives Sunday, but it should be Wednesday.
I think your formula is wrong:
Instead of
format(day(Date Table),"ddd")
Use
format(<Target Table>[<date column>],"ddd")
I.e. Omit the DAX DAY call. This is resulting in the day of the month (1..31) being passed to the format function.
When you use the DAY function in DAX, it returns the day of the month (1 through 31).
Thus DAY ( DATE ( 2020, 1, 1) ) = 1 which means you're trying to format the number 1 as a date. Integers are interpreted as days since 1899/12/30 when treated as a date, so 1 corresponds to 1899/12/31, which happened to be a Sunday. Thus FORMAT(1, "ddd") = "Sun".
There's no reason to get DAY involved here. You can simply write
Day = FORMAT ( 'Calendar'[Date], "ddd" )
I'm trying to manipulate a date value to go back in time exactly 1 ISO-8601 year.
The following does not work, but best describes what I want to accomplish:
date_add(date '2018-01-03', interval -1 isoyear)
I tried string conversion as an intermediate step, but that doesn't work either:
select parse_date('%G%V%u',safe_cast(safe_cast(format_date('%G%V%u',date '2018-01-03') as int64)-1000 as string))
The error provided for the last one is "Failed to parse input string "2017013"". I don't understand why, this should always resolve to a unique date value.
Is there another way in which I can subtract an ISO year from a date?
This gives the corresponding day of the previous ISO year by subtracting the appropriate number of weeks from the date. I based the calculation on the description of weeks per year from the Wikipedia page:
CREATE TEMP FUNCTION IsLongYear(d DATE) AS (
-- Year starting on Thursday
EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 5 OR
-- Leap year starting on Wednesday
(EXTRACT(DAY FROM DATE_ADD(DATE(EXTRACT(YEAR FROM d), 2, 28), INTERVAL 1 DAY)) = 29
AND EXTRACT(DAYOFWEEK FROM DATE_TRUNC(d, YEAR)) = 4)
);
CREATE TEMP FUNCTION PreviousIsoYear(d DATE) AS (
DATE_SUB(d, INTERVAL IF(IsLongYear(d), 53, 52) WEEK)
);
SELECT PreviousIsoYear('2018-01-03');
This returns 2017-01-04, which is the third day of the 2017 ISO year. 2018-01-03 is the third day of the 2018 ISO year.
LibreOffice Calc spreadsheet offers a function ISOWEEKNUM to return the standard ISO 8601 week number of the specified date.
I want the opposite.
➠ Given a standard week number, give me the date of the first day of that week (the Monday date).
Passing integers is acceptable. Also nice if able to pass a string in standard format.
Like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42" ) ➝ date of Monday of week 42 in week-based year 2017
Ideally, I would be able to pass a number 1-7 for Monday-Sunday to specify the day-of-week for which I want a date. Something like this:
DATE_OF_ISOWEEKNUM( 2017 , 42 , 1 ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( "2017-W42-1" ) ➝ date of Monday of week 42 in week-based year 2017
DATE_OF_ISOWEEKNUM( 2017 , 42 , 7 ) ➝ as above, but Sunday
DATE_OF_ISOWEEKNUM( "2017-W42-7" ) ➝ as above, but Sunday
Example:
Formula:
=DATE(B$1,1,$A4*7)+(2-WEEKDAY(DATE(B$1,1,$A4*7)))-7*(ISOWEEKNUM(DATE(B$1,1,1))=1)
Calculate the date of day (weeknumber * 7) in the year.
Correct the day to be weekday Monday.
Correct to 7 days before, if the first day of the year is in the
first ISO weeknumber.
I'm exporting aggregated data to MS SQL server from mongodb
mongo's $week does not evaluate to the same week as T-SQL datepart(wk, ) or datepart(isowk, ).
Does anyone know how to test the mongodb $week function so I can do some comparisons and see how best to resolve this issue?
Any help would be appreciated.
As far as I can see the differences fall into two main areas, the plain part being described in the documentation:
Weeks begin on Sundays, and week 1 begins with the first Sunday of the year. Days preceding the first Sunday of the year are in week 0. This behavior is the same as the “%U” operator to the strftime standard library function.
So the general concept here is that the value returned will be between 0 and 53 inclusive with week 0 being defined as the first week when the days are before Sunday.
So to paraphrase ( because the documentation gets the days wrong ) from the technet source for "datepart":
January 1 of any year defines the starting number for the week datepart, for example: DATEPART (wk, 'Jan 1, xxxx') = 1, where xxxx is any year.
And then (corrected):
The following table lists the return value for week and weekday datepart for '2007-04-21 ' for each SET DATEFIRST argument. January 1 is a Saturday in the year 2007. April 21 is a Saturday in the year 2007. SET DATEFIRST 7, Sunday, is the default for U.S. English.
So where you had documents like this:
{ "date" : ISODate("2007-01-01T00:00:00Z") }
{ "date" : ISODate("2006-12-31T00:00:00Z") }
{ "date" : ISODate("2006-01-01T00:00:00Z") }
The $week operator would return such as this:
{ "date" : ISODate("2007-01-01T00:00:00Z"), "week" : 0 }
{ "date" : ISODate("2006-12-31T00:00:00Z"), "week": 53 }
{ "date" : ISODate("2006-01-01T00:00:00Z"), "week" : 1 }
January 1st in 2006 was a Sunday and is considered the start of week 1, but where it was a Saturday it would be week 0 of 2007. The 31st of December in the previous year is Week 53.
In contrast the DATEPART considers Jan 1st 2007 and Dec 31st 2006 to be in Week 1 as the week ending on the first Sunday of the year. The Sunday is the default US English value but may differ and can in fact be set via SET DATEFIRST
So both have different opinions of where a date belongs in terms of the week of the year, but the general difference will be one with the other consideration days falling at the end of the previous year.
I wonder if anyone could help on this please? I need to show the current month as a 2 digit field. IE
January as 01
February as 02
March as 03
etc until
October as 10
November as 11
December as 12
The formula I am using is: ToText ("0"& Month(CurrentDate))
but shows January as 01.00
ie need to remove the decimal point and the decimal places
Many thanks, Rob
Try this:
ToText( CurrentDate, "MM")
The ToText function will automatically convert the date you are supplying to whatever format you want. You don't need to use the Month function. Per the documentation, you just supply the date and the output format. For the month, you use "MM".
ToText(CurrentDate, "MM")
According to the documention, these are the valid strings you can use
Pattern Result
d Numeric day of month without leading zero (1, 7, 31)
dd Numeric day of month with leading zero (01, 07, 31)
ddd Three day abbreviation of day of week (Mon, Sat)
dddd Full name of day of week (Monday, Saturday)
M Numeric month without leading zero (1, 7, 12)
MM Numeric month with leading zero (01, 07, 12)
MMM Three letter abbreviation of month (Jan, Feb, Mar)
MMMM Full name of month (January, February, March)
yy Last two digits of year (11, 14, 22)
yyyy Full four digits of year (2011, 2014, 2022)
To add to the above, if you need to return something like Mar-17 then:
totext({Command.DocDate},"MMM") + '-' + totext({Command.DocDate},"yy")