Monthly average from daily data - tableau-api

I have a dataset of energy efficient smart AC units. Each one has an ID, and each unit has daily data that represents the cost saved (in dollars) for each day.
I want to create a bar graph that shows the average savings, per month, per unit. I'm really struggling, however. AVG([Elecsavingscost]) only gets me the average daily savings in a given month. SUM([Elecsavingscost]) * 30 gets me pretty close to what I want, but of course, not all months have 30 days.
Is there a more intelligent way to do this? I'm presuming it's possible...

It can be very easily done using R software. Following is the code to convert daily data to monthly data
install.packages(c("zoo","hydroTSM")
library(zoo)
library(hydroTSM)
data=read.csv("data.csv")
data #data should contain 2 or more columns; 1st column should be date in
#English (U.K.) format, 2nd and subsequent columns should be your daily data
date Elecsavingscost
01-01-1984 18.8
02-01-1984 20.2
03-01-1984 19
04-01-1984 19.6
05-01-1984 21.8
06-01-1984 21.5
.
.
.
25-12-2014 13.6
26-12-2014 13.6
27-12-2014 16.2
28-12-2014 18.2
29-12-2014 16.7
30-12-2014 19.4
31-12-2014 18.5
x1 <- zooreg(data$Elecsavingscost, start = as.Date("1984-01-01"))
## Daily to monthly conversion
Elecsavingscost_monthly<- daily2monthly(x1, FUN=sum, na.rm=TRUE)
write.csv(Elecsavingscost_monthly,"Elecsavingscost_monthly.csv")

Related

Google Sheet - calculating attendance from moving date range

Good day folks, we have a Google Sheet with training attendance. We are meeting on weekly basis and calculate attendance from the past four months, last 36 month and historical total.
Situation: Currently, we calculate the attendance by assigning 2 (double training)/1 (normal training)/0 (canceled training) to the value of the training and attendee (2 on double, 1 on normal, 0 when absent) - and get attendance percentage by comparing the person's points sum to that of the trainings during the given period (4 months, 36 months, total).
Issue: The problem is that every time we add a training (new row in the tab), we need to manually change date range in the 4 month calculation and end date in the 36 months. I would love to automate this process that every time we add a new column, we would not have to change the date range.
Cells:
C4 = maximum points available per trainings in the last 18 months
D4 = maximum points available per trainings in the last 4 months
C5 and below = user's attendance in the past 18 months (his points generated in that timespawn/total available points*100)
D5 and below = user's attendance in the past 4 months (his points generated in that timespawn/total available points*100)
E3:3 = cells with dates when we have trainings
E4:4 = points awarded per that specific training
E5:5 and below = points gained by the member per attendance
Question: is there any way count a number of training points gained in the past 4/18 months by a specific person?
Thank you kindly
try:
=SUM(FILTER(E5:5; E$3:$3>=TODAY()-120; E$3:$3<=TODAY()))/D$4

Trending Percentage over time

When I am trying to calculate a percentage over time with the rolling weighted denominator, what is that called? The calculation is basically
Users With WiFi Activity/Users
The line graph that I have is graphed daily on the x axis but at each day, it is only calculating the day of so the percentage is extremely lower, but what I want is on the line graph, on day, the percentage of WiFi users rolling 30 up to that day is this % vs only day x $.
Is that called a moving average?
Also, how is that calculate?
What Data should look like
Day Percentage SUMTotalWiFiUsersRolling SumTotalUsersRolling
8/1 85% 1800 2000
8/1 81% 1700 2100
What Tableau is doing
Day Percentage SUMTotalWiFiUsersDayOnly SumTotalUsersRolling
8/1 30% 600 2000
8/1 35% 735 2100
You're right, that is a moving average. MA since the day that you're fixing the 30 days period at is moving (each new day the window jumps by one day forward)
Is your data at the day level of detail? If so, this is the table calc you need:
WINDOW_AVG([SUMTotalUsersRolling],-29,0)
In the formula, we're starting at 29 days backwards from this day (0). So the 30 day average is including today
Formula format:
WINDOW_AVG(<field to average>,<number of periods to start from>,<period to end at>)

Find and Rank Time Series MATLAB

I know there must be a simple way that I can learn to do this but I cannot imagine how to start. I am tasked with finding a top 10 matching daily wind power time series in a 30-day plus/minus window from the first day in the time series (Jan 1st) matching a single daily wind power time series and it is out of my level of experience in MATLAB. I have successfully done this matching a single time series of the current year with the exact calendar days from previous years, but I need a more robust searching method to find the best correlated time series in a +/- window of time. For example, I'm comparing a 120 day time series (without leap years) with 25 previous years during the same 120-day period (Jan-Apr). The end result will show me the top 10 time series with the years and Julian day or cumulative day listed and a correlation or RMSE value associated with it. My data looks like this arranged in a 365 (days) X 25 (years) array and I thank you very much for your help!
1182573 470528 1638232 2105034 1070466 478257 1096999
879997 715531 1111498 1004556 1894202 1372178 1707984
636173 937769 2119436 742710 1625931 1275567 1228515
967360 1103082 2218855 1643898 1822868 554769 1325642

Tableau - weekly average from daily data

Using Tableau 8.1.
Daily data like this:
Date Sales
1-1-14 $5
1-2-14 $2
...
6-15-14 $15
Which can be aggregated to weeks of course
Week 1 $15
Week 2 $12
Week 3 $10
Week 4 $13
etc.
I would like to get the weekly average of each month
So like this:
Weekly Average
Month 1 (weekly average of the weekly total sales) ($15+$12+$10+13)/4 = 12.5
Month 2
Month 3
Does that make sense? If ou simply put "average" in the tableau table, it gives the average daily value PER WEEK (or month) < - I don't want that. I want the average of the weekly totals per month.
Quite simple, actually.
Create these calculations
Unique Weeks = COUNTD(DATEPART('week',[Date]))
Weekly Average = sum([Sales])/[Unique Weeks]
Then simply report Weekly Average x Month (or Quarter or Year, etc.)
(Note: Some weeks have < 7 days).
This can be done very simply with one calculated field.
WINDOW_AVG(SUM([Sales]))
Then drag your Date pill onto the rows shelf twice, one aggregated to day, the other to week. Make sure pills are set to discrete (blue) and drag your Sales measure onto the shelf, also as discrete.

Calculate how many years there's left on a debt and print it in date format

I'm using Google Docs Spreadsheet and I want to calculate how many years there is left on a debt from a fixed date (YYYY-MM-DD), into a date (same formation).
Example: I started to pay off on a debt which are on 20 000, 2014-03-31. Every month, I'll pay 200 and the debt will be payed off 2022-03-31. If I change the pay sum (200) to another sum, the date will be based on the new sum and change the final debt year.
How can I accomplish this?
If you are satisfied with a more or less exact solution, you can write:
=A1+(30*D1/D2)
where:
A1 is your starting date (in date format), such as: 2014-03-31
D1 is your total amount of debt, in this example: 20000
D2 is your monthly sum of debt payed, in this example: 200
The formula simply counts how many months you need to clear the debt (D1/D2, which gives 100), and then multiples it by the average days of a month (30). Then it adds this amount of days to the starting date. Actually this example gives the result: 2022-06-17 as the final clearance of the debt.
As I said it's not fully exact as it counts 30 days as an average month and it does not count loop years, but I think that it can be used for your purpose.
I hope it helps.
UPDATE:
You'll get a little closer result to the exact value, if you use this:
=A1+(365*quotient(D1/D2,12))+(30*MOD(D1/D2,12))
The QUOTIENT function will calculate how many years are needed (in the example D1/D2 divided by 12). We multiply this value with 365 (the number of days in a year).
Then the MOD function calculates how many more months are needed after the years, which is the modulo of "D1/D2 divided by 12".
This function will give 2022-07-27 as a result for this example.