Calculate days between an interval with intck - sas

I'm trying to calculate the days between two dates for example 01JAN2020-30NOV2021 but without success. I tried: days=intck("days", start, end+1) but it does not work. Dates are numeric after PROC CONTENTS. Is this the problem? As an example I showed one date but I have to calculate days for 3000 records.
Thank you in advance

There is no interval named DAYS. You could use the DAY interval.
days=intck("day", start, end+1);
But since DATE values are just number of days you can also just subtract.
days=end - start + 1 ;

Related

Count number of days between multiple dates based on measure and sum each week

So, strange one to explain...
I have a table with the start dates of each person in project (each start day is the first Monday of the week)
I want to know how many people were in the project on any given week.
If I select two weeks in a slicer, for example
Week1
Week3
And there were 10 people in week 1 and 30 in week 3 the total should be 40.
How do I build a measure to do this.
Essentially I'm asking it to count the number of rows(project members) where the start date is >= each selected date and sum each individual result.
I hope this has made sense unable to share much due to work red tape
Thanks
Lloyd
I would do this in the following way:
Create a bin for the work week
Create a measure to count the bin from step 1.

How to graph by 7 day periods in Power BI

Power Bi gives you the option to look at data by Year, Quarter, Month, and Day. I want the ability to look at data by 7 day periods that start on a specific date (not necessarily Monday or Sunday). How is the best way to accomplish this? I am guessing it will be with a measure but I can't quite figure out what the measure should look like?
Here I know I can assign a day of the week to each row and then use Week Day on my date axis. My problem is I need to be able to put "Tuesday" in the second parameter instead of either 1. Sunday or 2. Monday.
Week Number = WEEKNUM(Sheet1[Date],2)
Thank you in advance!
IIUC, the following might work:
Week number = WEEKNUM(DATEADD([Date],1,DAY),2)

Calculate Daily Average Month To Date in PowerBI

In Power Bi my average matters per day is not stopping on the current day.
Avg Per Day = DIVIDE([Matters],SUM(Dates[IsWorkday]))
where IsWorkday = IF(ISBLANK(Dates[Holiday]),IF(Dates[DayOfWeekNumber]>1&&Dates[DayOfWeekNumber]<7,1,0),0)
and Matters = COUNT(BillingData[Item])
So today is the 27th of the month so 18 of 20 work days are completed for the
month. So need [matters]/18, not [matters]/20.
How do I factor that in to my average and not affect previous months.
Any help appreciated.
Sounds like you need to just add one more condition to your if statement to add in that the date is less than todays date. Check out this post. I think it might have the solution to your problem or at least give you the idea you need to solve the issue.
https://community.powerbi.com/t5/Desktop/Networkdays-DAX-function/td-p/38044

PowerBI - Week Number on X-Axis

I have a line graph in PowerBI and in my date dimension I have the Week Number for every date (note that this is a custom week number with the week starting on Friday).
Whenever I put it on a the x-axis, PowerBI groups all the weeks together, regarless of year... so Week 1 of year 2015 will be grouped together with Week 1 of 2016...
I think to myself: "Ok, no problem, I'll just add the Year after every week number so I'll have 1-2016, 2-2016, and so on."
Well PowerBI sees this concatenation as a string value so when I put that on the graph, it goes
1-2016, 1-2017, 2-2016, 2-2017, 3-2016, 4-2016, and so on....
I've tried sorting the new column by the old week number column, but it does the same thing. Any suggestions on how to accomplish this?
You're on the right track. I recommend a separate (hidden) sort column that sorts alphabetically (i.e. year first, then 2 digit week). In other words, 1-2016 = 201601.
This way, all the weeks for 2016 sort before the weeks for 2017, and the weeks sort in the right order too. (A 1 digit week would mean 20161 will be followed by 201610, which you don't want either.)

Number of sundays between two dates?

I am having problems with finding the number of sundays between two dates. I tried to use the intck () function to count number of weeks between two dates and since week in SAS starts on a Sunday I thought that was the right way. However now I am not so sure.
My dates go from 2007QI to 2013QII. I want to know the number of sundays in each quarter, so I have to look at the number of sundays between current quarter and previous (that is this date and lag (date)). When I use the intck() function I get 13 as the number of weeks in each quarter (except for one where I get 14).. i am not sure whether it is correct to assume that there are 13 sundays in each quarter?
intck is the correct function, but I would use weekday as the time interval. Ordinarily this assumes a 5 day working week, with Saturday and Sunday as weekends, but you can tweak it to use a 1 day working week, with Monday - Saturday as weekends (i.e. just count the number of Sundays).
data _null_;
format a b date9.;
a='01 nov 2016'd;
b='18 nov 2016'd;
Sundays = intck('weekday234567w',a,b);
put _all_;
run;