calculating excel formula using powershell - powershell

I am having below data in excel sheet (e.g. it's for 1 day and for 5 mins sample
So 2022-10-23 01:35:00 PM will have multiple rows, 2022-10-23 01:40:00 PM will have multiple rows and so on)
SLA sheet
SYMM_ID DATE INSTANCE Total Response Time Host MBs Read/sec Host MBs Written/sec Host Reads/sec Host Writes/sec
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.44 579.25 14.23 4405.09 142.27
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.26 29.89 0.97 4041.24 103.99
297900076 2022-10-23 01:30:00 PM L_PRDPRF 0.49 187.3 162.67 3779.49 7470.4
297900076 2022-10-23 01:30:00 PM L_PRDSTD 0.41 4.16 1.45 213.21 200.95
297900076 2022-10-23 01:30:00 PM L_NPRDSTD 0.53 0.01 0.03 0.03 3.31
297900076 2022-10-23 01:30:00 PM L_NPRDSTD 0.57 0 0.01 0 2.18
I am running the below formula and result I am getting in another sheet
=IFERROR(AVERAGEIFS(SLA!$D:$D,SLA!$C:$C,"*_L_*STD",SLA!$B:$B,$B20,SLA!$D:$D,"<>0"),"-")
The output of the above formula giving me 1 row. So for each date and time, the SLA sheet will have multiple rows but output is AVG of them as single row. so finally each date and time will have 1 row in other sheet.
for a 30 days month, the output sheet should have 122430 = 8640 rows ( 12 rows per hour, 24 hours a day and 30 day month)
The same I need to perform via powershell. I have done the formula part but the problem is I am not getting how to loop/perform that 8640 rows part
Please need suggestions on this. let me know if any details missed.

Related

PostgreSQL - How can I SUM until a certain hour of the day?

I'm trying to create a metric for a PostgreSQL integrated dashboard which would show today's "Total Payment Value" (TPV) of a certain product, as well as yesterday's TPV of the same product, up until the same moment as today, so if I'm accessing the dashboard at 5 pm, it will show what it was yesterday until 5 pm and today's TPV.
edit: My question wasn't very clear so I'm adding a few more lines and editing the query, which had a mistake.
I tried this:
select
sum(case when table.product in (13,14,15,16) then amount else 0 end) as "TPV"
,date_trunc('day', table.date) as "Day"
from table
where
date > current_date - 1
group by date_trunc('day', table.date)
order by 2,1
I only want to sum the amount when product = 13, 14, 15 or 16
An example of the product, date and amount would be like this:
product amount date
8 4750 19/03/2019 00:21
14 7840 12/04/2019 22:40
14 15000 22/03/2019 18:27
14 11715 19/03/2019 00:12
14 1054 22/03/2019 18:22
14 18491 17/03/2019 14:28
14 12253 17/03/2019 14:30
14 27600 17/03/2019 14:32
14 3936 17/03/2019 14:28
14 19007 19/03/2019 00:14
8 9400 19/03/2019 00:21
8 4750 19/03/2019 00:21
8 25000 19/03/2019 00:17
14 10346 22/03/2019 18:23
I would like to have a metric that always calculates the sum of the product value today up until the current moment - when the "product" corresponds to values 13, 14, 15 or 16 - as well as the same metric for yesterday, e.g., it's 1 PM now, I want today's TPV until 1 PM and yesterday's TPV until 1 PM as well!

Day and night average per day in R

I have a data set from april to october with registered data every 5 minutes per day. I want to get the average temperature and RH of day and night for every day, considering "day" from 7:30 to 18:30 and "night" for the rest of hours,
The table looks like this:
Date Time Temp RH
18/04/2018 00:00:00 21.9 73
18/04/2018 00:05:00 21.9 73
18/04/2018 00:10:00 21.8 73
18/04/2018 00:15:00 21.6 73
18/04/2018 00:20:00 21.6 72
18/04/2018 00:25:00 21.5 72
18/04/2018 00:30:00 21.4 74
And so on till october. I have tried codes from similar questions but for some reason or the other, I always get an error. In one example I saw that there is a column with "AM/PM" values to make this simpler, but then I'd have to create this new column for all the rows. Also tried with "hourly.apply" but it seems that the function doesn't exist.
What I want to obtain is this:
Date Time Temp RH
18/04/2018 day 25.8 80
18/04/2018 night 17.3 43
19/04/2018 day 24.2 73
19/04/2018 night 15.1 42
I typed the code:
> n=287
> T24_GH111 <- aggregate(GH111[,3],list(rep(1:nrow(GH111%%n+1), each=n, leng=nrow(GH111))),mean)[-1];`
But this will give me the average of 24 hours.
Thanks in advance!
Let's start with a simple example and create a dateframe with datetimes.
library(lubridate) # for datetime manipulation
# Creating simple example
Datetime <- c(as.POSIXct("2018-04-17 22:00", tz="Europe/Berlin"),
as.POSIXct("2018-04-18 01:00", tz="Europe/Berlin"),
as.POSIXct("2018-04-18 10:00", tz="Europe/Berlin"),
as.POSIXct("2018-04-18 13:00", tz="Europe/Berlin"),
as.POSIXct("2018-04-18 22:00", tz="Europe/Berlin"),
as.POSIXct("2018-04-19 01:00", tz="Europe/Berlin")
)
x <- c(1,3,10,20,2,5)
df <- data.frame(Datetime,x)
Now, we are using local_time() from the lubridate package to define a new day/night variable.
# Getting local time in hours
df$time <- local_time(df$Datetime, units ="hours")
# Setting day night parameter
t1 <- 7.5 # 07:30
t2 <- 18.5 # 18:30
df$dayNight <- ""
idx <- xor(t1 < df$time ,df$time < t2)
df$dayNight[idx] <- "day"
df$dayNight[!idx] <- "night"
To aggregate by day, we need to change the dates for all datetimes < 07:30. Fortunately, we have already set up the local time. So, let's use this for setting up a dummyDate variable. (This will be the resulting Date)
cond <- df$time < t1
# Using dummyDate for aggregate for dayNight values per day
df$dummyDate <- df$Datetime
df$dummyDate[nightCondition] <- df$Datetime[nightCondition] - days(1)
df$dummyDate <- floor_date(df$dummyDate, unit = "day") # flooring date for aggregation
df
Datetime x time dayNight dummyDate
1 2018-04-17 22:00:00 1 22 hours day 2018-04-17
2 2018-04-18 01:00:00 3 1 hours day 2018-04-17
3 2018-04-18 10:00:00 10 10 hours night 2018-04-18
4 2018-04-18 13:00:00 20 13 hours night 2018-04-18
5 2018-04-18 22:00:00 2 22 hours day 2018-04-18
6 2018-04-19 01:00:00 5 1 hours day 2018-04-18
Now, we have set up all variables to use the aggregate function to calculate the mean of x by dayNight and dummyDate
# Aggregating x value per dummyDate and daynight variables
dfAgg <- aggregate(df[,2], list(Date = df$dummyDate, Time = df$dayNight), mean)
dfAgg
Date Time x
1 2018-04-17 day 2.0
2 2018-04-18 day 3.5
3 2018-04-18 night 15.0

Selecting all data for records based on most recent date

MySQL client version: 5.0.24a
Hey Folks,
I have a table WorkOrders_errors that looks like this:
ID CO CAR NAME CAN BLN INDATE MODDATE EX
66897 461 57 KKLU KKLUSH9862088 AKLU6013312 1/27/2014 1:00 1/27/2014 1:00 -1
60782 461 57 KKLU KKLUHB21629300 AKLU6501153 1/26/2014 22:00 1/26/2014 22:00 1
74188 461 57 KKLU KKLUHB21629300 AKLU6501153 1/27/2014 10:00 1/27/2014 10:00 1
66645 461 57 KKLU KKLUSH8222080 AKLU6501744 1/26/2014 21:45 1/26/2014 21:45 1
63307 461 126 ZIMU ZIMUGOA321986 AMFU3037671 1/27/2014 1:15 1/27/2014 1:15 1
65081 461 24 CMDU CMDUAU1337382 AMFU3043761 1/26/2014 21:30 1/26/2014 21:30 1
72660 461 24 CMDU CMDUAU1337382 AMFU3043761 1/27/2014 9:30 1/27/2014 9:30 1
I need only the records with the most recent MODDATE, ie ID Record 74188, not 60782.
I have tried this a few ways, but without success. Most recently tried
SELECT * FROM (
SELECT * FROM WorkOrders_errors ORDER BY ModDate DESC) as tmp
GROUP BY can
ORDER BY can
'ALSO TRIED
SELECT t1.*
FROM WorkOrders_errors t1
WHERE t1.Can = (SELECT t2.Can
FROM WorkOrders_errors t2
WHERE t2.Can = t1.Can
ORDER BY t2.Can DESC
LIMIT 1)
These both seem to take a Huge amount of resources/time. The table only has about 80,000 rows.
Thanks anyone!

Suppress Group by Condition

I've a crystal report like this:
Page Header
2013 & 2014 Salesman Performance Report
Group Header
Salesman: {Salesman}
Month 2013 2014
Details
{Month} {2013Amt} {2014Amt}
Group Footer
Total: {#2013} {#2014}
Result:
2013 & 2014 Salesman Performance Report
Salesman: Billy
2013 2014
Jan 1,000.00 0.00
Feb 500.00 800.00
Total 1,500.00 800.00
Salesman: Keith
2013 2014
Jan 0.00 0.00
Feb 0.00 0.00
Total 0.00 0.00
Salesman: Candy
2013 2014
Jan (200.00) 0.00
Feb 0.00 200.00
Total (200.00) 200.00
Is it possible to suppress the salesman group "Keith" if there're no transaction on 2013 & 2014?
Thank you for the suggestions from craig & Siva. There's a problem, if the total sum for a salesman is 0 but there're transactions. How to handle it?
For example:
Salesman: Kitty
2013 2014
Jan (200.00) 0.00
Feb 200.00 0.00
Total 0.00 0.00
I can have the finally result now although I'm not sure the method is correct or not.
Create formula field Count1 & Count2 and input the following formula
Count1: If {2013Amt} <> 0.00 then 1 else 0
Count2: If {2014Amt} <> 0.00 then 1 else 0
Then input the following formula into Group header, details and group footer (section expert> Suppress)
Sum({#Count1},{Salesman})=0 and Sum({#Count2},{Salesman})=0
You will be able to do so, but not with a running total field--running total fields can only be used in the footer.
Instead, add the following conditional-suppressional formula to the salesman header, salesman footer, and details sections:
Sum({2013Amt},{Salesman})=0 And Sum({2014Amt},{Salesman})=0
In this case you need to supress Group header, details and group footer.
Go to the section expert and gor to the forumula of supress then write below code.
If {2013Amt} =0 and {2014Amt}=0
then true
else false.
For group footer write condition on sum of the group.

interval overlapping in tsql

i need to get splited intervals and the number of overlapping intervals, eg
basedata:
interval A: startTime 08:00, endTime 12:00
interval B: startTime 09:00, endTime 12:00
interval C: startTime 12:00, endTime 16:00
interval D: startTime 13:00, endTime 14:00
now i have a separate interval from 10:00 to 15:00 and have to determine what intervals are intersected at first. result should be something like:
1: 10:00 - 12:00 ( intersecting with interval A )
2: 10:00 - 12:00 ( intersecting with interval B )
3: 12:00 - 15:00 ( intersecting with interval C )
4: 13:00 - 14:00 ( intersecting with interval D )
this part works fine, the following causes the trouble:
i need some kind of weighting for parallel intervals. this also means, that it can occur that an interval-intersection must be splitted n times, if it's ( partly ) intersected by another one.
in the upper example the expecting result would be:
1: 10:00 - 12:00 -> weightage: 50%
2: 10:00 - 12:00 -> weightage: 50%
3.1: 12:00 - 13:00 -> weightage: 1oo%
3.2: 13:00 - 14:00 -> weightage: 50%
3.3: 14:00 - 15:00 -> weightage: 50%
4: 13:00 - 14:00 -< weightage: 100%
the splitting of interval 3 is caused by the intersecting with interval 4 between 13:00 and 14:00.
sql-server is ms-sql 2008.
thanks for help in advance!
If I understand what you're trying to do correctly, shouldn't your expected result be
1: 10:00 - 12:00 -> weightage: 50%
2: 10:00 - 12:00 -> weightage: 50%
3.1: 12:00 - 13:00 -> weightage: 1oo%
3.2: 13:00 - 14:00 -> weightage: 50%
3.3: 14:00 - 15:00 -> weightage: 50%
4: 13:00 - 14:00 -< weightage: 50%
since 13:00-14:00 is used twice?