How can I get the last day of the month as my end date on a BIRT report? - reporting

I am having issues getting the last day of month on my report.
I used the add month function to add a moth but it kept on giving me the first day of the next month. I only want the last day of the month as my end date and not the first day of the next month.

To get the last day of the current month enter the following Javascript:
now = new Date();
new Date (new Date(now.getFullYear(), now.getMonth() +1 , 1) - 1);

Related

Parameter Date of SSRS Visual Studio

I need help on developing the expression for a parameter. What i need is:
That the report gives me data of the day before when it´s Tuesday, Wednesday, Thursday and Friday, and when it´s Monday that it gives me the data of the 3 days before (of Friday, Saturday and Sunday). How can i put that in an expression of the Parameter?
I usually have the date parameter that checks the current date and if it's Monday, subtract the extra two days.
=TODAY.AddDays(0 - IIF(TODAY.DayOfWeek.ToString = "Monday", 3, 1))
Then the query would use this as the starting date range and yesterday as the end.
WHERE MY_DATE BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)
If the Date field has a timestamp then you'd need to convert that to a date.
WHERE CAST(MY_DATE AS DATE) BETWEEN #START_DATE AND CAST(GETDATE() - 1 AS DATE)

Day of Month must be between 1 and last day of month

Trying to write a query where I can see the format of a date using the query below
select to_date((substr(Key ,8,15)),'yyyymmdd') from Myrules
where LENGTH(substr(Key ,8,15)) = 8;
the data looks like this in the Key field
AA-FFL-20200706
AA-FFL-20200961
AZ-MDL-20200961
AZ-MGL-4
I'm getting the error saying "day of month must be between 1 and last day of month" Any idea what am I doing wrong above?
There's no day 61 in any month I know.
AA-FFL-20200961
AZ-MDL-20200961

Oracle - How to get date from YEAR, WEEKNUM and WEEKDAY?

I need to find the date of particular year, week, and weekday in oracle.
Is there a built-in function for this in oracle? or how can I achieve this?
Ex: If Year=2019, Week=22, Day=2(Tuesday), Then date should be '28-05-2019'.
Assuming "Week" and "Year" means week and year according to ISO-8601 you can use this function:
CREATE OR REPLACE FUNCTION ISOWeekDate(YEAR INTEGER, WEEK INTEGER, DAY INTEGER) RETURN DATE DETERMINISTIC IS
res DATE;
BEGIN
IF WEEK > 53 OR WEEK < 1 THEN
RAISE VALUE_ERROR;
END IF;
res := NEXT_DAY(TO_DATE( YEAR || '0104', 'YYYYMMDD' ) - INTERVAL '7' DAY, 'MONDAY') + ( WEEK - 1 ) * 7;
IF TO_CHAR(res, 'fmIYYY') = YEAR THEN
RETURN res + DAY - 1;
ELSE
RAISE VALUE_ERROR;
END IF;
END ISOWeekDate;
I think there is no built-in function for this, you will have to build one on your own.
below is one of the solutions you can make use of.
WITH FUNCTION getDate(p_year IN NUMBER, p_weeks IN NUMBER, p_day in NUMBER) RETURN DATE
IS
v_tmp date;
v_day number;
BEGIN
v_tmp := to_date('01/01/'||to_char(p_year),'dd/mm/yyyy');
v_day := to_char(v_tmp,'D');
RETURN v_tmp+(p_weeks-1)*7+p_day-(v_day)+1;
END;
SELECT getDate(2019,22,2)
FROM DUAL;
/
As per my NLS_TERRITORY settings, Oracle numbers the day of the week starting from Sunday, but from your example, you seem to be considering Monday as day 1 of the week. So, the same adjustment is made to the function to return the expected result.
Also, please note that with clause function is a new feature of Oracle 12c, if you happen to use an older version of Oracle, you will have to create the stored function before calling it.
Logically, the ISO week number is the occurrence of Thursdays in that (Gregorian) calendar year. The ISO year of an ISO week, is the Gregorian year in which the Thursday of that ISO week falls.
In the ISO schema, weeks always contain 7 days. Weeks start on a Monday, finish on a Sunday, and the days of that week are numbered 1-7.
This weekday numbering scheme often differs from that returned from built-in WEEKDAY functions and similar in different software packages (or requires particular database settings), which is something to be aware of. You will need available a function that returns the weekday of a particular date according to the ISO numbering scheme.
The first Thursday of the year can occur anywhere in the range 01-Jan to 07-Jan.
If the first Thursday falls on 01-Jan, then the first ISO week of that year will include days (29/31-Dec) from the previous Gregorian year.
If the first Thursday falls on 07-Jan, then the last ISO week of the previous Gregorian year will include days (01/03-Jan) from the current Gregorian year.
If the first Thursday falls on 04-Jan, then by implication the first ISO week of the year runs from Monday 01-Jan.
To devise an algorithm, the easiest approach is probably to establish on what weekday the 04-Jan falls in the given year, then apply the following calculation 4 - weekday. If the weekday of 04-Jan is found to be Thursday, the result will be 0. If it is Monday, the result will be 3 (4-1). If it is Sunday, the result will be -3 (4-7). We will store this offset for use after the next step.
We can derive a provisional day-of-year-offset from the ISO week and day numbers as follows: (((iso_week - 1) * 7) - (4 - iso_day)).
We then apply the offset derived in the first stage for the final day-of-year-offset. This is an offset from 04-Jan of the given Gregorian year. This offset may be a minus figure, if the relevant day falls prior to 04-Jan of the given year.
Given that day-of-year-offset, we can then use built-in functions to produce 04-Jan of the given year, and apply the day-of-year-offset to produce the final Gregorian date.
For example, given 2019-W01-1.
2019-01-04 is a Friday, so it's weekday is 5. The result of the first step is -1 (4-5). The result of the second step is -3 (((1-1)*7) - (4-1)). Added together they produce a day-of-year-offset of -4. 04-Jan-2019 offset by -4 results in 31-Dec-2018.
And that is our result: 2019-W01-1 = 2018-12-31.

Date Logic - Tableau

Could someone help me achieve the date logic as below:
I work for a fiscal year starting from Oct to Sep, once I finish the fiscal year and step into a new one I want the last month of last fiscal year's sales for reference until the end of new fiscal year. For example, now in Sep'17 the fiscal year ended but I want Sep'17 sales number to be shown in graph as reference until next Sep'18 later that I want Sep'18 number to be shown until Sep'19 and so on so forth.
The logic I have arrived is not a permanent solution as it requires editing once I step into Year 2018, it is as below:
IF YEAR([Invoice Date]) = YEAR(TODAY()) AND
DATEPART('month', [Invoice Date]) = 9 THEN [Sales] END
once I step into Year 2018, I need to make change to the above logic like:
IF YEAR([Invoice Date]) = YEAR(TODAY())**-1** AND
DATEPART('month', [Invoice Date]) = 9 THEN [Sales] END
Is there a way to achieve permanent solution without editing the logic?
Try this:
Create 2 calcualted fields for start date and end date, Where start date is september last year and end date is september current year.
Start Date:
DATEADD('month',-1,MAKEDATE(YEAR(TODAY())-1,MONTH(TODAY()),01 ) )
End Date:
DATEADD('month',-1,MAKEDATE(YEAR(TODAY()),MONTH(TODAY()),01 ) )
Now one more calcualted field which will create the filter and add the formula to filter to get the require data.
[Order Date]>=[Start Date] AND
[Order Date] <=[End Date]
Add to filter and then select True
Note: Here today function means start of the fiscal year that you need to manage.

SSRS Add Months in current date with last day of month

I want to add months with last day in current date by using
=dateadd(dateinterval.month, +4, DateAdd("d",-(Day(today)), Today))
expression.
output is
current_date = 12/02/2014
finish_date = 03/30/2014
The problem is that finsih_date month is 03(March) and last day of March is 31 but my parameter showing 30.
It may look like:
=DateAdd("d", -1, DateSerial(DatePart("yyyy", finish_date), DatePart("m", DateAdd("m", 1, finish_date)), 1))
For every day in a given month it calculates the last day of the given month. So for 03/30/2014 you would get 03/31/2014.
Calculation works like: Build new date which is set to the first day of the following month of a given date. Substract 1 day. Which is the last day of the month before. As we added 1 month it is the last day of the month of the given date.
Edit
Code with finished_date = TODAY + 4 Month (finished_date + 1 so it is TODAY + 5)
=DateAdd("d", -1, DateSerial(DatePart("yyyy", DateAdd("m", 5, TODAY())), DatePart("m", DateAdd("m", 5, TODAY())), 1))

Resources