Netsuite saved search formula that sums distinct values within a date range - formula

I am trying to create a saved search of time entries in Netsuite.
Under criteria, I have specified a date range. This varies as this is an available filter
For the purposes of this example, the date range is 1/4/2020 to 10/4/2020
The first column ('Total Customer Billable Hours') in this sums all time entries that are coded against project task type 'billable project'. The formula I am using for this:
Formula (Numeric), sum, Case when {project.task_type}='Billable' then {durationdecimal} else 0 end
For the second column, I want the sum of hours the employee would normally work (in the time period specified under criteria-1/4/2020 to 10/4/2020 in this example)
The formula I am using to sum this is
Formula(numeric), sum, {timesheet.workcalendarhoursdecimal}
However, this is multiplying the employee's weekly hours by the number of time entries that make up the 'Total customer billable hours' figure
i.e. if an employee works a 40 hour week, the formula is multiple 40 x 36 (the number of time entries that make up the customer billable figure for example)
What would the correct formula be so that the second column is only summing the employee's work calendar hours for the period specified in the criteria/available filter selection?

Try changing sum to maximum:
Formula(numeric), maximum, {timesheet.workcalendarhoursdecimal}

Related

Calculate Running Count in Power BI based on two column context evaluation

I have a column called Weekly User Escalation which is a binary column indicating whether a user has been escalated or not in a specific calendar week. 1 for yes, 0 for no.
The data's granularity is dates (in one calendar week dates can also be missing and not always equal 7 days). So, for any calendar week, I can have 1-7 rows in my dataset.
Now, I want a column which sums up the escalation levels per user per CW. I.e., if User 1 has been escalated in Calendar Week 1 and 2 and not in CW 3, it should return 1+1+0=2, and so on.
What I tried already is this:
CALCULATE(SUMX('Data', MAX('Data'[Weekly User Escalation])), ALLEXCEPT('Data', 'Data'[User], 'Data'[Calendar Week]))
The output shows the sum of all the 1s and 0s in for that user, which in my case shows 13, since there were 13 rows which were "1" for a particular CW in my dataset. I want that only the MAX value from the column Weekly User Escalation, which is always 1, is counted AND ONLY ONCE for every CW.
Try with:
WeekWithEscalation = CALCULATE( Countrows( VALUES('Data'[Calendar Week]), 'Data'[Weekly User Escalation] = 1 )
If we put to visualization UserName and measure [WeekWithEscalation] that should work.

Excel - How do I match a minute in time series with specified minute to return max value from another column?

I am trying to extract the max values of CO2ppm (column E) that were logged every second over 1 hour (column D) for a total of 60 minutes (rows ~3300). I have column D for time (in HH:MM:SS) and CO2ppm (numeric). I have 50 CO2 samples that I collected that correspond with a minute (e.g. I collected sample #1 at minute 20:54 in F2), but the data is logging every second within that minute, and I want the the highest CO2 ppm in that minute).
The =MAX(IF(D:D=A2,E:E)) works to return the max value CO2ppm when I use the target value as the date (A2) for the entire day of sampling, but it does not work when I try to match my target minute (F2, 20:54) with the column D (HH:MM:SS). I tried to convert this column to text using =TEXT(D:D,"H:M") so that the target value will match the values of minute, excluding all of the seconds, but with no luck.
How can I match my minute (F2) with the range of rows that have that minute (20:54:xx, column D) to find the max value in column E?
Example data:
Thank you!
An easy way to do this would be to add a helper column with the timestamp stripped of the second component.
However in case that is not an option, you could use a formula like the following, which strips out the seconds from the timestamps in column D:
=MAX(IF((D2:D5-SECOND(D2:D5)/86400)=F2,E2:E5))
Depending on your version of Excel, you may have to confirm the formula with Ctrl+Shift+Enter.

How do I compute the moving average age of a product from the first day it is purchased?

I have a series of random data points with order date, expiry date and product category.
I am trying to compute 2 age variables, wherein 1 would compute the rolling age using just the order date (hence no expiry date) between order dates.
In other words, I don't need age determined based on current date but ones' relative to each data point in the data. As such, the average would keep increasing as more products are purchased and first ones get old. The second age variable would essentially cap each order by expiry date, which would mean the rolling average would not necessarily be increasing.
I am trying to do this using R or Tableau.

R - Filter Dates by Time Window without including weekends

Is there a way to window filter dates by a number of days excluding weekends?
I know you can use the between function for filtering between two specific dates but I only know one of the two specific dates, with the other date I would like to do is 4 days prior in business days only (not counting weekends).
An pseudo-example of what I am looking for is, given this wednesday I want to filter everything up to 4 business days beforehand:
window(z, start = as.POSIXct("2017-09-13"), end = as.POSIXct("2017-09-20"))
Another example would be if I am given this Friday's date, the start date would be Monday.
Ideally, I want to be able to play with the window value.

Apache Drill: Group by week

I tried to group my daily data by week (given a reference date) to generate a smaller panel data set.
I used postgres before and there it was quite easy:
CREATE TABLE videos_weekly AS SELECT channel_id,
CEIL(DATE_PART('day', observation_date - '2016-02-10')/7) AS week
FROM videos GROUP BY channel_id, week;
But it seems like it is not possible to subtract a timestamp with a date string in Drill. I found the AGE function, which returns an interval between two dates, but how to convert this into an integer (number of days or weeks)?
DATE_SUB may help you here. Following is an example:
SELECT extract(day from date_sub('2016-11-13', cast('2015-01-01' as timestamp)))/7 FROM (VALUES(1));
This will return number of weeks between 2015-01-01 and 2016-11-13.
Click here for documentation

Resources