How do I get a dynamic list of months down a column between two dates in the month year format in Google Sheets?
example:
Start date: 5/18/2016
End date: 5/24/2019
Jan 2016
Feb 2016
Mar 2016
..
...
May 2019
=ARRAYFORMULA(UNIQUE(TEXT(TO_DATE(ROW(
INDIRECT("A"&DATEVALUE(B1)):
INDIRECT("B"&DATEVALUE(B2)))), "mmm yyyy")))
Related
I am looking for DAX expression to show me monthly figure for last financial years. Here is an example of the information;
The figure is accumulated since the starting of 31 Jan 2017 or earlier which I have no information. The data I have does not have a monthly view but Year to Date (YTD).
How could I structure the DAX so that it would be able to find out what is the figure for the month.
For example, Jan 2017 $2,000 , Feb 2017 $5000 (included figure from Jan 2017), March 2017 $8000 (included Jan 2017 and Feb 2017).
How can it be done to have the monthly view ?
Date............. Balance Sheet Amount.......View
31-Dec 2017................24,000.......................YTD *1
31-Jan 2018................24,010.......................YTD *1
28-Feb 2018................24,310.......................YTD *1
31-Dec 2018................30,000.......................YTD *2
31-Dec 2019................31,000.......................YTD *3
31-Dec 2020................40,000.......................YTD *4
30-June 2021................5,000.......................YTD *5
Let's say your current table does not contain previous balance, then it will be easier to obtain the current month movement with the following formula:
Current Month = Sheet1[YTD Bal] -
CALCULATE(SUM(Sheet1[YTD Bal]),
FILTER(Sheet1,Sheet1[Index] = EARLIER(Sheet1[Index]) - 1))
Before you start the dax calculation, you will need to add index column first and here is the output:
I have a column with a year and a ISO week. I would like to get the corresponding date, but at the moment my formula is wrong.
I have the following table:
Year Week
2020 52
2020 53
2021 1
2021 2
I used in power query editor the following formula:
Date.StartOfWeek(Date.AddWeeks(#date([Year], 1, 1), [Week]), Day.Monday)
and I obtained:
Year Week Date
2020 52 28.12.2020
2020 53 04.01.2021
2021 1 04.01.2021
2021 2 11.01.2021
What I would like to have instead:
Year Week Date
2020 52 21.12.2020
2020 53 28.12.2020
2020 1 04.01.2021
2021 2 11.01.2021
For example, in DAX, this works:
Date = DATE([Year],1,-2)-WEEKDAY(DATE([Year],1,3))+[Week]*7
But I would prefer to have it in power query because my data source needs to be updated regularly. Thank you for your attention!
In case you have the same problem, this works now:
Date.AddDays((Date.AddDays(#date([Year],1,1),-4)),(-Date.DayOfWeek(Date.AddDays(#date([Year],1,1),-4)) + [Week]*7))
I need to create a field of previous year total sales in the current year column.
Here is an example based on it being 2018 today: in 2018, it should be 2017 total sales(full year), in 2019, it should be 2018 Sales(jan-apr would be only months in may), and 2020 should be blank, as there are no data in 2019 yet, etc.
Use the calculation to make it as "Date-1".
My typical requirement is that I want to subtract two Dates cast as timestamp. The Minuend (First parameter) is the current date and the Subtrahend(second parameter) is stored separately as DD, MM and YYYY in three columns. The final output should be a discrete year as number. I am playing with something like :
SELECT (TO_DATE('05-DEC-2013') -
CASE LENGTH(CAND_DOB_DD)
WHEN 1 THEN
CAST(TO_DATE('0'||CAND_DOB_DD||'-'||CAND_DOB_MM||'- '||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP)
ELSE
CAST(TO_DATE(CAND_DOB_DD||'-'||CAND_DOB_MM||'-'||CAND_DOB_YYYY,'DD-MM-YY HH24:MI:SS')
AS TIMESTAMP) / 365 END YEAR
FROM CANDIDATE
The Year part as Integer will be used for a very sensitive calculation. Please suggest if the above piece of SCRIPT will yield the desired result. Thanks in advance.
For most purposes you could just use the Months_Between() function to determine the number of months between two dates, and then divide by 12 etc.. Note that the number of months is an integer when comparing two dates that have the same day of the month or are both the last day of the month.
This is tricky when it comes to leap years.
Do you count 28th Feb 2015 to 28th Feb 2016 as exactly one year, when 28th Feb 2015 to 29th Feb 2016 is one day longer but plainly is a year?
What about 29th Feb 2016 to 28th Feb 2017, or 28th Feb 2016 to 28th Feb 2017?
Think carefully about these boundary cases, but Months_Between() is likely to be your best choice.
I am trying to truncate several dates of a certain month to the start of the week, except the ones that start in the previous month.
Example:
Wednesday 5 Dec 2012 should be truncated to Monday 3 Dec 2012
Saturday 1 Dec 2012 should not be truncated to Monday 26 Nov 2012
For truncating the dates I am using:
date_trunc('week', dates.d)
The problem is that Saturday 1 Dec 2012 still gets truncated to Monday 26 Nov 2012
Can I add a constraint to it, so that it takes the month into account?
Thanks in advance :)
NOTE: I am using version 9.2
GREATEST(date_trunc('week', dates.d), date_trunc('month', dates.d))