I have been using a SAS code I have written to group a historical dataset (that gets updated weekly) by grouping them into weeks (Sunday - Saturday = 1 group). I have been using INTNX.
Our definition of a week has now changed and is Tuesday through Monday. How can I update the code below to make that adjustment. I have been messing with the 'Week' function and trying to add days to the end to make this change but to no success.
Currently, I am using:
WEEKOF = INTNX('Week', SasDate,0);
Where "SasDate" is the date of each record in my dataset.
Any help would be greatly appreciated.
Thanks,
Michael
Simply change it to
weekof = intnx('week.3',sasdate,0,'beginning') ;
Sun = 1, Mon = 2, Tue = 3, etc.
Related
Good Afternoon,
For a project I need a method to show with a year filter which rows were active in that year based on a start and an end date.
Example dates:
25th Oct 2019 - 14th Jul 2022
1st Feb 2020 - 1st Jan 2022
25th May 2016 - 24th May 2018
With A filter on 2020 this would mean:
Show
Show
Don't show
I have an approach that works but it only works if you enter a specific date as a filter. My measure works like this:
I have a separate datetable that I use as a filter, this value is stored in the variable selDate, and the isActive variable checks whether this variable date falls in between.
My DAX code:
Find_active_row =
var selDate = SELECTEDVALUE(Dates[Date])
var isActive if(and(selDate>=firstdate(Table[Startdate]),selDate<=firstdate(Table[enddate])),1,0)
return isActive
So my problem is I want to filter by year and now I need to filter a specific day for it to work. I'm actually looking for a replacement for firstdate because this doesn't work if I make Table[Startdate].year because it won't be a date field anymore. I hope my problem is clear and any help is appreciated :)
How would I go about setting up a rolling 12 month period in Django without any year.
I am trying to plot the academic year but the problem I am finding mainly due to my lack of knowledge is that I have to set the year in datetime
I would like to try and create a start and end date for the academic year which runs from the beginning of April to the end of March every year however I have to include the year in all the objects such as datetime.
Is there a way for me to set a start and end date regardless of the year, the only way I can think of so far is to take the end of March as a start date and then count 12 months from then.
As always, thank you for the help.
timedelta might be help full. check out documentation
import datetime
start_date = datetime.datetime.now()
end_date = start_date + datetime.timedelta(days=365)
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.
I have used the following to get the stating day of the month
multiemp[Day] - WEEKDAY(multiemp[Day],2)
For example if my date us 22 May 2018, after using the above query, got the expected out put.i.e., 20 May 2018
Now I tried to get the month name by using the above query and format function
format(month(multiemp[Day] - WEEKDAY(multiemp[Day],2)),"mmm")
results were not expected, instead of may January is getting populated.
when verify with the following month function expected results arrived .i.e, 5
month(multiemp[Day] - WEEKDAY(multiemp[Day],2)
but only issue in changing the month number to month name
Please find below:
formulas used
weekstartday = multiemp[Day] - WEEKDAY(multiemp[Day],2)
weekstartday_month = month(multiemp[weekstartday])
Month_name = format(multiemp[weekstartday_month],"mmm")
another_ans = format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"mmm")
another_answer_date = dateadd(multiemp[Day],-weekday(multiemp[Day],2),day)
EDIT: Day 2
Modified the datatype of the column to date time/timezone.
after refresh the data didn't change
Found out the solution
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")
Thanks in advance
Format the column instead of repeating the column DAX statement.
Column = FORMAT(*nameOfYourStartOfWeekColumn*,"mmm")
Because FORMAT(...,"MMM") or FORMAT(...,"MMMM") takes as an argument a date types and non numeric types, try this
format(dateadd(multiemp[Day],-weekday(multiemp[Day],2),day),"MMM")
If you want the starting day of the week as monday, then,
format(dateadd(multiemp[Day],-weekday(multiemp[Day],3),day),"MMM")
EDIT
Verify that date column is date or date\time type.
Solution 1:
mnname = format(multiemp[weekstartday].[Date],"mmm")
Solution 2:
Month_name = format(date(YEAR(multiemp[weekstartday]),MONTH(multiemp[weekstartday]),day(multiemp[weekstartday])),"mmm")
I know I can change the date field granularity to week in AWS Quicksight, and I can also display the date by week number. But as far as I understand, Quicksight defines the start of a week on Sunday, and I need it to be Monday.
Is there any way to start the week on Monday in AWS Quicksight?
Here is a formula for a calculated field you can add that will group your dates by weeks starting on Mondays. You should be able just replace {date_date} with your field name and copy/paste this into the formula box (including the newlines) and it will do the trick.
addDateTime(
1,
'DD',
truncDate(
'WK',
ifelse(
extract(
'WD',
{date_date}
) = 1,
addDateTime(
-1,
'DD',
{date_date}
),
{date_date}
)
)
)
This field will equal the Monday that starts the week your date falls into.
You can put this all in one line but I added the line breaks for readability.
It essentials checks if the date is on a Sunday, and moves it to the previous week and then just adds a day to the normal trunc function so that the weeks begin on Monday.
Acoording to the documentation
https://docs.aws.amazon.com/quicksight/latest/user/truncDate-function.html
WK: This returns the week portion of the date. The week starts on Sunday in Amazon QuickSight.
you can use filters to start like here
This is still an issue when using filters and rolling dates as weeks in analytics.
There is an open thread in the AWS community forum.
https://community.amazonquicksight.com/t/starting-weeks-on-monday-show-gaps-on-custom-weekly-groupings/4222
As a I workaround for this, I would recommend defining a column (either in the dataset or as a calculated field) that represents the year_week_iso (ie. 2023-W01 or 202301 if you prefer to have an integer value).
This column can then be used to group data in order to show trends over time when the week begins on a Monday.
The integer version of this column can also be leveraged to show the most current week of data by setting up a Top 1 filter that is based off the max(year_week_iso_integer) →
example Amazon Quicksight filter to get current week