Percentage change day by day in Google DataStudio - percentage

I would like to generate an easy daily percentage change of var in Google Data Studio day-by-day as done below:
Basically, as shown in C4, -65.31% indicates that from day 2 to day 3 there was a decrement of 65.31% of var value and so on.

Created an Editable Google Data Studio Report to demonstrate the process below:
1) dayPLUS1 (Calculated Field: Data Source-level)
Create a metric that adds 1 to the Day field:
day + 1
For YYYYMMDD Date field calculations, use the formula below:
CAST(Date AS NUMBER )+1
2) Reaggregation (Self Blend)
Perform a self blend where the left Data Source includes values for the Day field and the respective metric, whilst the Data Source on the right includes the Day Plus 1 values:
Data Source 1
Join Key: day
Metric: var
Data Source 2
Join Key: dayPLUS1
Metric: varPLUS1 (rename the var metric)
3) Table (Blended Data Source)
Create a Table with the field to display the Daily Percentage Difference:
Dimension: day
Sort: day in Ascending order
Metric 1: var
Metric 2 (Calculated Field; Type: Number > Percent):
(SUM(var) / SUM(varPLUS1)) - 1

Related

defining business day where hours are not same as standard days

While working on a sales report for an entertainment company ( bars and nightclubs), I normally just sum sales and I get the daily sum of sales. but I was communicated that their business day starts at 6 am of each and closes at 5:59:59 am the next day. basically sales reported Monday are the sales from 6 am Sunday thru 5:59:59 am Monday.
the company operates throughout the US so we have multiple time zones as well
the table has the following columns:
Transaction id, location, Transaction_datetimeLocal, TransactionDateTimeUTC, Transaction amount
how do I define / filter the calculation to be from 6am one day to 5:59:59 am the next day USING Power BI / DAX
TIA
In Power BI you have your table with the local time. You need to add a calculated column with the following DAX formula:
Business Time = 'Table'[Local Time] - TIME(6, 0, 0)
From this new column you could the create your business date with
Business Date = 'Table'[Business Time].[Date]
This is how it looks in the Data view:

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.

How to join tables and time align for cohort analysis in R

Background
I have 2 tables I wish to join in R to perform a cohort analysis. Table 1 is a large data table, with observations of hundreds of objects, and timestamps for each observation. Table 2 holds individual timestamped events associated with individual objects. The cohort analysis would be to align the observations from every object so that the adjusted time = 0 would be the point in time of the event for that object.
Table 1: object_id, ts, observation_type, reading
Table 2: object_id, ts, event_type, notes
The complication is that there will be periodic drift of the baseline due to seasonal effects. Therefore, for the analysis to be meaningful, the observations must be adjusted against the average of all objects.
The top level plan using tydr, dplyr & ggplot2
Create timestamped seasonal baseline - average of all readings for each observation type (there are 3).
Filter out objects where event occurs.
Adjust data set for filtered set against baseline.
time adjust filtered dataset so events are all coincident.
Plot results.
Disclaimer
I've literally only just read R for data sceintists, and have only ever written about 100 lines of code, so I'm a rank novice. Could a data scientist offer hints on the approach above to structure my analysis?
Pseudo-Code and Plan
To create seasonal baseline with timestamp.
seasonal_average_reading1 <- table1 %>%
filter(observation_type = type1) %>%
group_by(ts) %>%
filter(ts, count > 10) %>%
summarise(seasonal_average = mean(reading))
select(ts, seasonal_average)
No clue where to start. First I need to search Table 2 for all isntances of the event I'm interested in, and grab out the object_id's that are affected. Then I need to filter Table1 for only the objects in that list! Is that do-able?
... %>%
mutate(adj = reading - seasonal_average)
For each object, the ts of the event will be taken, and used to adjust the timestamp of the observations. Repeat for all devices and somehow keep the data together? Help!
gplot2
data = time adjusted, filtered dataset.
aes(x=adjusted time, y = average of adjusted dataset)
what else do I need.
Data Samples
event
{
deviceId: '410DF5',
ts: 1604391197,
date: 1604368332,
jobs: [ 'Insulation' ],
notes: 'blah blah blah'
}
DATA
id,ts,seqNum,rssi,type,reading
410D08,1604482547,714,-118,hum,61
410D08,1604482547,714,-118,temp,23.2
410D08,1604482547,714,-118,hum,61
410D08,1604482547,714,-118,temp,23.2
410D08,1604482547,714,-118,hum,62
410D08,1604482547,714,-118,temp,23.2
2C7568,1604482585,2,-98,hum,68
2C7568,1604482585,2,-98,temp,22.3
2C7568,1604482585,2,-98,hum,68
2C7568,1604482585,2,-98,temp,22.2
2C7568,1604482585,2,-98,hum,68

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

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}

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