Showing results between 5 to 14 days - if-statement

I am coding some customer service scripts and the aim is to show the results from 5 - 14 days after the deadline/date.
For example: date= 2016-01-20.
So five days after would be 01-25 and 14 would be 02.03 and the results should display it inbetween 5 to 14 days.
I have made an if statement:
if (date>= date.addDay(5) && date<= date.addDay(14))
{
print("Ticket ID: " + se.getField(0) + "\n" + "Ticket date: " + se.getField(1) + "\n\n");
}
functions addDay - adds a days to the date.
getField - gets fields ID and deadline/date.
In the results of this script I get also results from 2015. So there is something wrong with the logic of if-statement.
How should How to make it display results between 5 days after deadline to 14 days after deadline.

Related

how to apply distinct and group by in django or in postgres?

table production
code
part
qty
process_id
1
21
10
10
1
22
12
10
2
22
15
10
1
21
10
12
1
22
12
12
I have to extract data like based on process, every process has multiple part but I can't take every part's data, so that have to distinct on code for getting process wise summation of qty.
how to get data like this in postgresql or in django
process_id
qty
10
27
12
12
I tried in this way
Production.objects.values('process').distinct('code').annotate(total_qty=Sum('quantity'))
The following query gets your desired result, but from your snippet I'm not sure this is the logic you had in mind. If you add more detail I can refine the answer.
SELECT process_id, SUM(qty) qty
FROM production
WHERE part=22
GROUP BY process_id

Tableau - need to compare the number of records that came in last 7 days to the number of records that came in the last 7 days -1

In Tableau I have a db containing records with a create date [create date]
I need to compare the number of records that came in last 7 days to the number of records that came in the last 7 days -1 .
And show the change as a percentage.
Thanks
Assuming today is August 31th, last 7 days should be Aug 24-30, excluding today.
sum(if DATEDIFF('day',[Order Date],DATE(TODAY()-1)) <= 6 then 1 end )
If "7 days -1" means last 7 days starting from one day prior to yesterday, this second range is Aug 23-29.
sum(if DATEDIFF('day',[Order Date],DATE(TODAY()-2)) <= 6 then 1 end )
According to your different needs, you can just use this formula [(A/B)-1] in order to get the change in %:
(
sum(if DATEDIFF('day',[Order Date],DATE(TODAY()-1)) <= 6 then 1 end )
/
sum(if DATEDIFF('day',[Order Date],DATE(TODAY()-2)) <= 6 then 1 end )
)
-1

Converting if/and statement into an array formula

I'd like to convert the following formula:
=IF(A2:A=1,"Under an hour",IF(AND(A2:A<48,A2:A>23),"1 Day",IF(A2:A>=24,int(A2:A/24)&" Days",ROUNDUP(A2:A) &" Hours")))
into an Array formula. Currently it doesn't work because AND statements don't work in Array Formulas but I'm not really sure how to get it working without the and (and without embedding 24 different IF statements)
I basically just want to return user-readable text in column B relating to how many hours are shown in A:
0 0 Hours
1 Under an hour
2 2 Hours
23 23 Hours
24 1 Day
25 1 Day
47 1 Day
48 2 Days
49 2 Days
100 4 Days
Change AND(A2:A<48,A2:A>23) to (A2:A<48)*(A2:A>23):

PowerBI running Total formula

I have a dataset OvertimeHours with EMPLID, checkdate and NumberOfHours (and other fields). I need a running total NumberOfHours for each employee by checkdate. I tried using the Quick Measure option but that only allows for a single column and I have two. I do not want the measure to recalculate when filters are applied. Ultimately what I am trying to do is identify the records for the first 6 hours of overtime worked on each check so that they can get a category of OCB and all overtime over the first 6 hours is OTP and it does not have to be exact (as demonstrated in the output below). I have only been working with Power BI for about a month and this is a pretty complex (for me) formula to figure out...
EMPLID CheckDate WkDate NumberOfHours RunningTotal Category
124 1/1/19 12/20/18 5 5 OCB
124 1/1/19 12/21/18 9 14 OTP
125 1/1/19 12/20/18 3 3 OCB
125 1/1/19 12/20/18 2 5 OCB
125 1/1/19 12/22/18 2 7 OTP
124 1/15/19 1/8/19 3 3 OCB
*Edited to add the WkDate.
Edit:
I have tweaked my query so that I have the running total and a sequential counter now:
Using the first 12 records, I am looking to get the following results:
I can either do it in a query if that is the easiest way or if there is a way to use DAX in PowerBI with this dataset now that I have the sequential piece, I can do that too.
I got it in the query:
select r.CheckDate,
r.EMPLID,
case
when PayrollRunningOTHours <= 6
then PayrollRunningOTHours
else 6
end as OCBHours,
case
when PayRollRunningOTHours > 6
then PayRollRunningOTHours - 6
end as OTPHours
from #rollingtotal r
inner
join lastone l
on r.CheckDate = l.CheckDate
and r.EMPLID = l.EMPLID
and r.OTCounter = l.lastRec
order by r.emplid,
r.CheckDate,
r.OTCounter

Coldfusion crontime incorrectly running on weekend

I have a scheduled task that needs to run three times a day, on each weekday. The setup surrounding the task is Coldfusion, and it is in the Crontime format. It should run at 11:30, 15:45 and 18:30 server time.
For some reason the task is occasionally running on weekends, which it should not do.
Here are the three strings for each of the days:
0 30 11 ? * 1-5
0 45 15 ? * 1-5
0 30 18 ? * 1-5
Can anyone point out to me why the task is sometimes running on weekends? Is there a mistake in my string?
The Coldfusion crontime documentation can be found here:
According to This, 1 = Sunday.
Days-of-Week can be specified as values between 1 and 7 (1 = Sunday) or by using the strings SUN, MON, TUE, WED, THU, FRI and SAT.
Try replacing 1-5 with MON-FRI?
An example of a complete cron-expression is the string "0 0 12 ? * WED" - which means "every Wednesday at 12:00:00 pm".
Individual sub-expressions can contain ranges and/or lists. For example, the day of week field in the previous (which reads "WED") example could be replaced with "MON-FRI", "MON,WED,FRI", or even "MON-WED,SAT".