Day add in SSRS for weekday - reporting

i want to achieve the following I want to set the default date to the following business day. That would add one day for all weekdays unless it is Friday, if day is Friday than it add 3 days for Friday.
I am using the statement below but it is not working. It is adding 3 days for other days besides Friday in ssrs report.
= IIF(Weekday(Today()) <=3, DateAdd("d", 1, Today()), DateAdd("d", 3, Today()))
Example - 18/05/2018 today will be displayed 21/05/2018 And if date is 21/05/2018
then it will display 22/05/2018
Thanks for your answer.

I have created below logic on my local box and it works.
=DateAdd("d", IIF(Weekday(Today())=6, 3, IIF(Weekday(Today())=7, 2, 1)), Today())
I have added check that if Weekday returns 6(Friday) then add 3 days to Today date
else if Weekday returns 7(Saturday) then add 2 days to Today date
else add 1 day to Today date.

Related

Sort Date Dimensions By Custom Financial Years in Power BI

I am trying to sort the week and month column below (Week Ending Date)according to FY as currently, months are in alphabetical order.
YearWeek ReportDate Work order Week Ending Date FinancialYrSort
202135 22/08/2022 12:00:00 AM WO7094852 28/08/2022 2
202202 3/01/2022 12:00:00 AM WO7465604 9/01/2022 1
202201 27/12/2021 12:00:00 AM WO7690126 2/01/2022 6
202153 26/12/2022 12:00:00 AM WO7467312 1/01/2023 6
202130 18/07/2022 12:00:00 AM WO6947586 24/07/2022 1
I've created the Financial Yr Sort column to be used for sorting -
Financial Yr Sort = If(MONTH('22a Planned Maintenance Efficiency'[reportDate]) > 6, MONTH('22a Planned Maintenance Efficiency'[Week Ending Date]) - 6, MONTH('22a Planned Maintenance Efficiency'[reportDate] + 6))
This generates July months from No 1 and goes on.
When I try to sort Weekending dates by Financial year an error message pops up. Please see the 2nd picture.
Can someone help me to sort this out?
Please note I want show the line graph by week. Please refer to the 3rd picture.

Can't get monthy CarbonPeriod to behave as desired

In the project I'm working on I have a daily command that basically checks the date of the last record in the database and tries to fetch data from an API from the day after and then each month after that (the data is published monthly).
Basically, the last record's date is 2019-08-30. I'm mocking as if I were running the task on 2019-09-01 with
$test = Carbon::create(2019,9,1,4);
Carbon::setTestNow($test);
I then create a monthly period between the next day of the last record's date and the last day of the current month like so:
$period = CarbonPeriod::create($last_record_date->addDay(), '1 month', $last_day_of_current_month);
Successfully generating a period with start_date = 2019-08-31 and end_date = 2019-09-30. Which I use in a simple foreach.
What I expected to happen is that it runs twice, once for August and once for September, but it's running only once for the start date. It's probably adding a month and going past the end date, but I don't know how to force the behaviour I'm looking for.
TL;DR:
$period = CarbonPeriod::create('2019-08-31', '1 month', '2019-09-30');
foreach ($period as $dt) {
echo $dt->format("Y-m") . "<br>\n";
}
This will print just 2019-08, while I expect 2019-08 and 2019-09. What's the best way to achieve that?
Solution :-
You can store actual date in $actual_day and current date for occurring monthly in $current_day. Put a check on comparing both dates, if not matched then make it on the same day it will skip 30,31 case in case of February month.
$current_date = $current_date->addMonths(1);
if($current_date->day != $actual_day){
$date = Carbon::parse($date->year."-".$date->month."-".$actual_day);
}
Your start date is 2019-08-31. Adding a month takes you to 2019-09-31. 2019-09-31 doesn't exist so instead you get 2019-10-01, which is after your end date. To avoid this I'd suggest you use a more regular interval such as 30 days.
Otherwise you're going to have to rigorously define what you mean by "a month later". If the start date is 31st Jan is the next date 28th February? Is the month after 28th or 31st March? How do leap years affect things?

Get a Specific WeekDay date after a date

I am trying to implement a delivery process that occurs at specific days of week for each region. So, in a Region that delivers on Tuesdays and Thursdays I need to be able to get next eligible date based on the date the product will be available. So, if I will have it read on the 5th, O need to get the date for the next Tuesday or Thursday.
I started implementing it on Carbon, but I and creating a lot of loops through dates, testing dates and checking if its valid. something of getting product availability date and checking each day after it if its a monday Tuesday or Thursday ... etc ///I am sure, using Carbon, will have a better way to do it.
Any hint on how to do that ?
Thanks for any help!
Define a date:
$date = Carbon::now();
Now you have to get the day:
$day = $date->dayOfWeekIso
If $date is monday, then you will get a integer and that would be 1. That is because: 1 (monday), 2 (Tuesday), ..., 7 (sunday).
Now that you have this number you just need to apply some simple logic.
If the number you get is a 2 (Tuesday) then you will need to add two days to your $date in order to get the delivery date:
$delivery_date = $date->addDays(2);
If your day is equal 4 (Thursday), then you need to add 6 days to your $date so that would give you the next Tuesday:
$delivery_date = $date->addDays(6);
I think that's what you want! I hope it helps!

VBScript DateDiff month

I am having a problem about getting the month datedifference between two dates.
Here is a sample:
DateDiff("m","2014-10-17","2014-10-30")
The above code returns 0 months since it is less than a month. But,
DateDiff("m","2014-10-17","2014-11-01")
returns 1 which should not be since it is still 15 days.
My problem is I want to see if these two dates already exceed a month but it seems that it calculates 1 month only when the month part of the date is changed.
DateDiff calculates the span between two timestamps with the precision defined in the first parameter. From what you described in your question and comments you rather seem to be looking for something like this:
ds1 = "2014-10-17"
ds2 = "2014-10-30"
d1 = CDate(ds1)
d2 = CDate(ds2)
diff = DateDiff("m", d1, d2)
If diff > 0 And Day(d2) < Day(d1) Then diff = diff - 1
WScript.Echo diff & " full months have passed between " & ds1 & " and " & ds2 & "."
You can calculate day difference between two dates using 'DateDiff("d",date1,date2)'.
Then calculate number of full-month by dividing 30 days.
Following is an example.
monthDiff = int(DateDiff("d","2014-10-17","2014-11-01") / 30)
As you know, days of months differs by month. For example, November has 30 days and December has 31 days.
If you wish to use 30 days a month when first day is on November, and to use 31 days a month whe first day is on December, the code need a table of days of months and routine to handle month information.

WebI Adding Weekend Values to Last Working Day in cross tab

Based on "Day" I should calculate the sales in Cross tab.
Saturday & Sunday values should be added only for Friday (Last working day). Below examples give an idea...(cond: if "DAY is Fri then add values for Fri+Sat+Sun)
Please assist. I'm struggling hard with the formulas in WebI
To give more detailed view..Actually i'm using Cross tab --> Day wise across organization.
Day----USA-----UK-----INDIA
Day----USA-----UK-----INDIA
THU-----23------ 12-----36
FRI------65------12------10
SAT------9--------16-----24
SUN------2--------24----56
FRI------3------ 10-----37
SAT-----29------ 06-----87
SUN-----03------04-----13
Result should be: DAY only Fri = (Fri + Sat + Sun) rest same values
Day----USA-----UK-----INDIA
THU-----23------ 12-----36
FRI------76------52------90
SAT------9--------16-----24
SUN------2--------24----56
FRI------3------ -20-----137
SAT-----29------ 06-----87
SUN-----03------04-----13
If you create a variable with the following formula, and replace the Day dimension in your current cross tab, you should get the output that you need:
=If [Day] InList ("SAT";"SUN") Then "FRI" Else [Day]
Basically, if the value for Day is SAT or SUN, it will return FRI, else it will return the original value. Web Intelligence should then automatically aggregate the values accordingly.

Resources