Individual start date per month - excel

together
how do I get it in PowerPivot or as Dax formula out that for my internal / individual months the beginning of the month from 31.120.2018 for January 2019 receive?
So, that I get the January in the PowerPivot calendar table already from 31.12.2018 and then in the 4-4-5 weeks cycle?
So
31.12.2018 + 28 days = January
31.12.2018 + (28 days * 2) = February
31.12.2018 + (28 days * 2) + 7 days = March
Does anyone have an idea?
Best Regards

First I create a calendar table, this is the simple part, I took a random start and end for testing:
CalendarDates = CALENDAR(DATE(2012;12;20);DATE(2021;1;5))
Then I added the column WeekNumber, this is to the greorgian calendar. A bit complicated because microsoft simply starts counting with 1 on the first of january..
WeekNumber =
var wNrfirstDayJanNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;1);2)
var fullWeekNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;7);2) = 1 //If day 7 of week is still first week, its a full week
var wNr31Dex = WEEKNUM(DATE(CalendarDates[Date].[Year];12;31);2)
var wNr31DexPrevYear = WEEKNUM(DATE(CalendarDates[Date].[Year]-1;12;31);2)
var wNr = WEEKNUM(CalendarDates[Date];2)
var pbi4JanWeekNrNextYear = WEEKNUM(DATE(CalendarDates[Date].[Year] + 1;1;4);2)
var pbi4JanWeekNr = WEEKNUM(DATE(CalendarDates[Date].[Year];1;4);2)
var wNrComp = if (pbi4JanWeekNr =2; wNr - 1; wNr)
return if(NOT(fullWeekNextYear) && wNr = wNr31Dex;IF(pbi4JanWeekNrNextYear = 2; wNr31Dex;1);if(wNrComp = 0; wNr31DexPrevYear; wNrComp))
last step is to create the Month based on the week number:
Month =
var quater = FLOOR((CalendarDates[WeekNumber] - 1)/13; 1)
var quarterWeek = MOD(CalendarDates[WeekNumber] - 1 - (quater*13);13)
var monthNr = FLOOR(quarterWeek/4;1)
var month445 = if (monthNr = 3; 2; monthNr) + quater * 3 + 1
return if (month445 = 13; 12;month445)
Note: I corrected week 53 in the last quarter so it becomes 4-4-6. You need to do your own math if you want it different.
End result:

Related

Node JS: calculating number working in each month between a two dates

I am trying to develop a code to generate number of working days in each month between two selected dates:
Eg: Start Date is 20-Oct-2022 and End Date is 14-Feb-2023.
I am able to generate net working days between two dates, however not for each month between the two dates.
I am expecting the code to provide output as:
Net working days in
Oct'22 is 8,
Nov'22 is 21,
Jan'23 is 22 and
Feb'22 is 10.
var startDate = new Date('20/10/2022');
var endDate = new Date('14/02/2023');
var numOfDates = getBusinessDatesCount(startDate,endDate);
function getBusinessDatesCount(startDate, endDate) {
let count = 0;
const curDate = new Date(startDate.getTime());
while (curDate <= endDate) {
const dayOfWeek = curDate.getDay();
if(dayOfWeek !== 0 && dayOfWeek !== 6) count++;
curDate.setDate(curDate.getDate() + 1);
}
return count;
}
like in above example you can calculate number of working days between two dates.

Generating bulk dates

I wanted to ask if anyone knows a way of generating bulk dates. I want to know about how can I generate all of the dates and times between 20130631_0000 till 20151231_2359
The month limit is 0-12
The day limit is 0-31
and the part you see after underscore is hour and minute, the hour limit is 00 till 23 and the minute is from 00 till 59. It's basically YYYYMMDD_HHMM
Few examples:
20130810_1154, 20140103_2357, 20150722_1049, 20140103_2358, 20140103_2359, 20140104_0000, 20140104_0001, 20140105_1159, 20140105_1200
If you simply want to print each date to the console:
let date = new Date(2013,6,31,0,0);
const endDate = new Date(2015,12,31,23,59);
const padWithZero = num => num.toString().padStart(2, '0');
while (date <= endDate) {
const year = date.getFullYear();
const month = padWithZero(date.getMonth()+1);
const day = padWithZero(date.getDate());
const hour = padWithZero(date.getHours());
const minute = padWithZero(date.getMinutes());
console.log(`${year}${month}${day}_${hour}${minute}`)
date = new Date(date.getTime() + 60000)
}
Try this
function convertStringToDate(date){
var year = date.substring(0,4)
var month = date.substring(4,6)
var day = date.substring(6,8)
var hour = date.substring(9,11)
var minute = date.substring(11,13)
return new Date(parseInt(year), parseInt(month), parseInt(day), parseInt(hour), parseInt(minute) )
}
function addMinute(date){
var new_date = date;
new_date.setMinutes(date.getMinutes()+1)
return new_date
}
function getDatesBetween(start_date_str, end_date_str){
var start_date = convertStringToDate(start_date_str)
var end_date = convertStringToDate(end_date_str)
dates = []
date = start_date
while(date.getTime() !== end_date.getTime()){
dates.push(new Date(date))
date = addMinute(date)
}
dates.push(end_date)
return dates
}
function pad (str, max) {
str = str.toString();
return str.length < max ? pad("0" + str, max) : str;
}
function convertDateToString(date){
var year = date.getFullYear().toString()
var month = pad(date.getMonth().toString(),2)
var day = pad(date.getDay().toString(),2)
var hour = pad(date.getHours().toString(),2)
var minutes = pad(date.getMinutes().toString(),2)
return year + month + day + "_" + hour + minutes
}
var start_date_str = "20130620_1224"
var end_date_str = "20130621 1224"
dates = getDatesBetween(start_date_str, end_date_str)
formatted_dates = dates.map(convertDateToString)
console.log(dates.length)
console.log(dates[dates.length-1])
console.log(formatted_dates.length)
console.log(formatted_dates[dates.length-1])

x pages Question: calculate working day Error

I try use computed field to calculate leave and working days. The error form show as below
script to count the working days
var nDateStart = session.createDateTime(document1.getValue("StartDate")).toJavaDate();
var nDateEnd = session.createDateTime(document1.getValue("EndDate")).toJavaDate();
var syear = #Year(nDateStart)
var smth = #Month(nDateStart)
var sday = #Day(nDateStart)
var startdate = #Date(syear,smth,sday)
var eyear = #Year(nDateEnd)
var emth = #Month(nDateEnd)
var eday = #Day(nDateEnd)
var enddate = #Date(eyear,emth,eday)
var weekends = "1:7"; //assuming your weekend is Saturday and Sunday
var holidays = "#Date(2019;8;12):#Date(2019;12;25)"; // assuming your holiday is 12 August and 25th December
var formula = "#BusinessDays(" + startdate + ";" + enddate + ";" + weekends + ";" + holidays + ")";
return session.evaluate(formula);
Date/time constants in Lotus formula language are enclosed in square brackets, which you can clearly see in the documentation for #BusinessDays. Try this:
var formula = "#BusinessDays([" + startdate + "];[" + enddate + "];" + weekends + ";[" + holidays + "])";
return session.evaluate(formula);
You need to calculate a valid formula before you can submit it to session.evaluate. The string you submit isn’t a valid formula. E.g the your parameter is just an unquoted string.
Remove the startdate and enddate and replace it with something like ”#Date(“+syear+”;”+smonth+”;”+”;”+sday+”)” that should give you the formula you seek.

Trying to calculate the end of the next day in node.js

I'm trying to calculate the end of the next day for any given date as an expiry date.
So if the input is eg 10/26/2013 16:36:46 then I'd like to get 10/27/2013 23:59:59 and 7/31/2013 16:36:46 would give me 8/1/2013 23:59:59
It gets obviously difficult with leap years and when the next day is a new month. So I tried to use the dateParse function which gives me a number that I can easily add 86400000 (full day in milliseconds) and then I want to use basically the reverse of dateParse (turn a number into a date object) so that I can then take out the date component and replace the time component with 23:59:59
Here's my code which doesn't work - setTime doesn't seem to be the right function and makes my next_day variable "undefined"
var next_day = call_start.dateParse + 86400000; // adding a full day to it
next_day = next_day.setTime;
var day = next_day.getDate;
day = (day < 10 ? "0" : "") + day;
var month = next_day.getMonth + 1;
month = (month < 10 ? "0" : "") + month;
var year = next_day.getFullYear;
var hour = 23;
var min = 59;
var sec = 59;
var expiry = year + ":" + month + ":" + day + ":" + hour + ":" + min + ":" + sec;
console.log ('Streak expires at: ' + expiry);
You can use the set* functions to modify the date:
var date = new Date('7/31/2013 16:36:46');
date.setDate(date.getDate() + 1);
date.setHours(23);
date.setMinutes(59);
date.setSeconds(59);
console.log(date);
// Thu Aug 01 2013 23:59:59 GMT+0200 (CEST)

Date in X-Axis - .Net Charts

i am working in .Net Charts. i want to show date in X-Axis. For ex : if i select Last 52 Weeks, then i should show the chart for last 52 weeks, whereas those 52 weeks start date should be in x-axis. I am not having any idea, how to do this..I had tried with the code..
DateTime Frm = sessionManager.ChartViewPeriodFrom;
DateTime To = sessionManager.ChartViewPeriodTo;
double min = Frm.ToOADate();
double max = To.ToOADate();
Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = min;
Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = max;
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 7;
Here i am getting the Frm as "9/17/2011 12:00:00 AM" But, in the chart the minimum date starts from "9/21/2011 12:00:00 AM". How to fix this...
I had tried like this also..[ Edited Part ]
Chart1.Series["Series1"].XValueType = ChartValueType.Date;
Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = (new DateTime(2011, 09, 17, 12, 00, 00)).ToOADate();
Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = (new DateTime(2012, 09, 08, 12, 00, 00)).ToOADate();
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 7;
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
After a long search...i had fixed my above issue...but still i dont know how it works...
Chart1.ChartAreas["ChartArea1"].AxisX.IntervalAutoMode = IntervalAutoMode.VariableCount;
Chart1.Series["Series1"].XValueType = ChartValueType.Date;
DayOfWeek ds = DayOfWeek.Wednesday;
double dblIntervalOffset = Convert.ToDouble(ds);
Chart1.ChartAreas["ChartArea1"].AxisX.IntervalOffset = dblIntervalOffset;
Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = min;
Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = max;
Chart1.ChartAreas["ChartArea1"].AxisX.Interval = 7;
Chart1.ChartAreas["ChartArea1"].AxisX.IsMarginVisible = false;
Indexed attribute must be set for series data.

Resources