i want last day last year,what is the function for that.
example if i put date SYSDATE the i should get
2018-12-31.
if 2018-02-28 then it should be 2017-12-31
Last day of year is always December 31. You can just subtract 1 from the year and add 12/31 to it. You could use GET_DATE_PART and MAKE_DATE_TIME functions.
LAST_DAY(ADD_TO_DATE(TRUNC(SYSDATE,'Y'),'MM',-1))
See below explain with example
TRUNC(SYSDATE,'Y')---->01/01/2022
(ADD_TO_DATE(TRUNC(SYSDATE,'Y'),'MM',-1))--->01/12/2021
LAST_DAY(ADD_TO_DATE(TRUNC(SYSDATE,'Y'),'MM',-1))-->31/12/2021
if you want next year last month
ADD_TO_DATE(LAST_DAY(ADD_TO_DATE(TRUNC(SYSDATE,'Y'),'MM',-1)),'MM',24)
Related
How to get sales of Last Week, Last One Month, Last Six Month, Last Year sales based on selected weekending dates from slicer filter. By using DATESINPERIOD function I'm getting results for last week but when I'm using same function for last 1 Month, 3 Months, 6 Months & 1 Year it is giving me blank values. How to get values for this particular months.
This is how I'm doing my calculation.
enter image description here
It is giving me results for last week but not for previous months which I wanted.
Note: In my slicer I'm using WeekEnding Dates which look like these 22/01/2023, 15/01/2023, 08/01/20223.
Any help would be greatly appreciated. Thank you.
I have various needs for time calculations, but can't get the basic syntax right. The measure
First Day of Year = STARTOFYEAR('Calendar'[Date])
returns 1/1/2019, which is the earliest date on my calendar table. Today's date being Jun 2022, I want it to return 1/1/2022.
Related question: In order to return the first day of the fiscal year (October 1 of the prior year) I would expect something like
First Day of Fiscal Year = STARTOFYEAR(DATEADD('Calendar'[Date],-3,MONTH))
But this returns the same result, 1/1/2019. Desired result is 10/1/2021
If you want it reference this (the current) year, you need the TODAY() function.
eg:
First Day of Year = date(year(TODAY()),1,1)
First Day of Fiscal Year = date(year(today())-1,10,1)
if you want to get the first Date of the year of a table containing more Years you have to filter the date Table:
CALCULATETABLE(STARTOFYEAR('Calendar'[Date]), 'Calendar'[Year]=year(today()))
I'm struggling to get the same period of last month.
I want to compare the current month period, for instance, today is 16June2021 so I want to get the sales from May 1st to May 16th.
I'm using this formula but I get the whole month total:
Prev MTD = calculate(sum(Sales[Sales_Amount]),DATEADD(filter(DATESMTD(Sales[Sale_Date]),Sales[Sale_Date]<=today()),-1,MONTH))
Creating a table with DATEADD(filter(DATESMTD(Sales[Sale_Date]),Sales[Sale_Date]<=today()),-1,MONTH), I also get every day of last month.
Is it mandatory to use a Date Table? Already tried but the results came empty.
Is it something regarding my date format? From the import it comes as date/time format.
Thank you very much
Try with:
Prev MTD = calculate(sum(Sales[Sales_Amount]),filter(ALL(Sales[Sale_Date]),Sales[Sale_Date] >= DATE( YEAR(TODAY()), MONTH(TODAY())-1, 1) && Sales[Sale_Date]<=today()))
where order_date between '2022-08-01' and DATE_SUB(CURRENT_DATE(),32)
last month 31 days that's why i am calculated 32 days.
if last month 30 day than you need to calculate 31 days.
I currently use the below measure to retrieve a value for the previous week, however as it's now week 1 of a new year, the field is returning "blank" as it cannot find any previous weeks.
How would I adapt my measure to include something along the lines of... if week 1 use the last week of the previous year, if not use the previous week.
VAR CURRENT_WEEK = WEEKNUM(TODAY()) return
CALCULATE(AVERAGE(DATA_TABLE[VALUE]),
FILTER (DATA_TABLE, WEEKNUM(DATA_TABLE[DATE]) = CURRENT_WEEK -1))
Thanks in advance for your help
I would suggest using a start date and calculating the weeknum from that date. For example, if you choose 1 Jan 2018 as start date, then 1-7 Jan 2018 would be week 1 and first week in 2020 would be week 105. This would solve your issue.
The method you are using becomes really hard to handle if your data has multiple years. Weeknum 1 would denote the 1st week of 2020, 2019 and all the other years. This will mess up the calculation. The above method will make sure you have a unique number for a week.
Date WeekNum Month Year
5/2/2018 Week 1 May 2018
6/1/2018 Week 1 June 2018
How would you get the WeekNum from the Date?
The WeekNumber needs to be week number of the particular month and not the Year.
One approach would be to take the day of the month and divide by seven:
WeekNum = ROUNDUP(DIVIDE(DAY(TableName[Date]), 7), 0)
You can use the next formula
1 + WEEKNUM(usage_users[row_date]) - WEEKNUM(STARTOFMONTH(usage_users[row_date]))
This gives you the number of the week.
basically you need to use STARTOFMONTH and WEEKNUM together:
Here is a good video explaining it also:
https://www.youtube.com/watch?v=Oq5WOmo94_Q