I have a graph that compares transactions from the last 7 days (including the current day), to the 7 days before that.
However, I've noticed that sometimes during the day, the order of the days is incorrect.
When I open the report again it is the correct, without me doing anything to fix it.
The above graph was created on Sunday morning, and the Saturday and Friday values are switched around. Since it's Sunday morning, the graph should start on Monday, and end on Sunday.
Later on, it displayed as it should.
The data is as follows (unfortunately I could only pull data as it was when the graph was shown correctly.) There are 2 products that are grouped together in the graph.
Brand Date DepositAmount DayOfWeek WeekSeries
B 10/02/2014 1630 Monday Previous Week
A 11/02/2014 13717 Tuesday Previous Week
B 12/02/2014 2460 Wednesday Previous Week
A 13/02/2014 4941 Thursday Previous Week
A 18/02/2014 9194 Tuesday Current Week
B 19/02/2014 1947 Wednesday Current Week
A 20/02/2014 4185 Thursday Current Week
B 21/02/2014 273 Friday Current Week
A 22/02/2014 2521 Saturday Current Week
B 22/02/2014 1118 Saturday Current Week
A 23/02/2014 1438 Sunday Current Week
B 23/02/2014 105 Sunday Current Week
A 14/02/2014 4958 Friday Previous Week
B 14/02/2014 1023 Friday Previous Week
A 15/02/2014 2465 Saturday Previous Week
B 15/02/2014 1208 Saturday Previous Week
A 16/02/2014 3495 Sunday Previous Week
B 16/02/2014 680 Sunday Previous Week
A 17/02/2014 2726 Monday Current Week
B 17/02/2014 1177 Monday Current Week
A 10/02/2014 4938 Monday Previous Week
B 11/02/2014 1543 Tuesday Previous Week
A 12/02/2014 7891 Wednesday Previous Week
B 13/02/2014 5490 Thursday Previous Week
B 18/02/2014 4726 Tuesday Current Week
A 19/02/2014 9009 Wednesday Current Week
B 20/02/2014 459 Thursday Current Week
A 21/02/2014 6012 Friday Current Week
In SSRS, the graph is defined as follows:
Category Groups: DayOfWeek (sorted by Date (A to z))
Series Groups: WeekSeries (sorted by WeekSeries (A to Z)).
Any ideas what may be causing this issue?
I think the issue is in your Category Group sort - you are Grouping by DayOfWeek but then sorting by Date which has multiple values. The first row for Friday could get the Current Week Date or the Previous Week Date at random.
To fix this, for the Category Group sort, I would derive a "Relative DayOfWeek" value, something like:
= Abs ( DateDiff ( DateInterval.Day , Today() , Iif ( Fields!WeekSeries.Value = "Current Week" , Fields!Date.Value, DateAdd ( DateInterval.Day , 7 , Fields!Date.Value ) ) )
Related
I need to handle specific scenario in StorProc where I need to do date calculation excluding Sat & Sun. Weekends are holiday I need to handle the data within working days.
I have implemented below code
if (purchase_date = (trunc(sysdate)-2) or purchase_date = (trunc(sysdate)-1)) Then
specific operation
As I have to exclude Sat & Sun by above implementation is giving wrong results obliviously . For example if today is Monday it has to give me back the date of Friday, my implementation is giving me Saturday or Sunday. I need to calculation with dates for weekdays only. Any help would be appreciated.
Thanks
To compare it to the previous week day, you can use:
IF purchase_date = TRUNC(SYSDATE)
- CASE TRUNC(SYSDATE) - TRUNC(SYSDATE, 'IW')
WHEN 0 THEN 3
WHEN 6 THEN 2
ELSE 1
END
THEN
-- Do something
NULL;
END IF;
TRUNC(date_value) - TRUNC(date_value, 'IW') will count the number of days since the start of the ISO week (which is always midnight on Monday).
Note: Do not use TO_CHAR(date_value, 'D') in an international setting as it will give a different result depending on which country you run it in (the week starts on Friday in Bangladesh, Saturday in some Middle-Eastern countries, Sunday in America and Monday in most of Europe).
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)
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.
I would like to have a DAX equivalent of the following SQL code:
SELECT DATEADD(week, -52, '2018-05-05')
--Result: 2017-05-06 00:00:00.000
2018-05-05 was a Saturday, I would like to see the same Saturday for the previous year: 2017-05-06 (as shown on the the SQL above)
In DAX, the DATEADD method allows to add/subtract by year, quarter, month and day intervals only. Is there any other function that allows to add or subtract weeks?
Thanks!
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))