Tableau sum by condition - tableau-api

I have a data like this
Date Temperature Load
2017-08-05 7:45:00 PM 10 5
2017-08-05 7:46:00 PM 10 4
2017-08-05 7:47:00 PM 10 2
2017-08-05 7:48:00 PM 10 1
2017-08-05 7:49:00 PM 10 5
.........
In Tableau, how can I sum the Load by hours and plot scatters?

I would drag SUM(Load) onto Rows and AVG(Temperature) onto columns and discrete hour of Date onto Details. That would give you a scatter plot like

Related

How to average monthly data using a specific method in Matlab?

I have the following vector of monthly values (vectorA). I put the date related info next to it to help illustrate the task but I work with just the vector itself
dates month_in_q vectorA
31/01/2020 1 10
29/02/2020 2 15
31/03/2020 3 6
30/04/2020 1 8
31/05/2020 2 4
30/06/2020 3 3
How can I create a new vectorNEW according to this algorithm
In each quarter the first month is the original first month
In each quarter the second month is the average of first and second month
In each quarter the third month is the average of all three months
So that I get the following vectorNEW by manipulating the original vectorA in a loop given this the re-occuring pattern above
dates month_in_q vectorA vectorNEW
31/01/2020 1 10 10
29/02/2020 2 15 AVG(10+15)
31/03/2020 3 6 AVG(10+15+6)
30/04/2020 1 8 8
31/05/2020 2 4 AVG(8+4)
30/06/2020 3 3 AVG(8+4+3)
... ... ... ...
An elegant solution was provided by the user dpb on mathworks website.
vectorNEW=reshape(cumsum(reshape(vectorA,3,[]))./[1:3].',[],1);
Further info below
https://uk.mathworks.com/matlabcentral/answers/823055-how-to-average-monthly-data-using-a-specific-method-in-matlab

Tableau: Calculated Field based on Dimension and Measure

I'm trying to set up a look at YoY based on quarters, thus (Q1 2016 Rev/Q2 2015 Rev) - 1.
My data is in quarters, so I'm trying to set up a calculated field with (Rev at Current Quarter / Rev at (Current Quarter - 4)) - 1
But I'm not sure how to set up that dependency in Tableau.
Thanks for reading
EDIT:
Example of Data
quarter_id | quarter_revenue
10 | 200
11 | 430
12 | 250
13 | 300
14 | 405
15 | 493
16 | 299
So quarter_id 10 corresponds to 2015 Q1, then 11 is 2015 Q2, etc. Currently I can set this into Tableau and use Quick Table Calculation: Percent Difference on Quarter_Revenue which gets me the difference for id 11 and 10 (2015 Q2 and 2015 Q1).
What I want to do is look a year ahead however, and do this calculation 4 quarters ahead. So to compare 2015 Q1 vs 2016 Q1, I would need to do look at id 14 and id 10, and the calculation for Percent Difference would be (405/200)-1.

daily to monthly sum in matlab of multiple years

My data is excel column. In excel sheet one column contain last 50 years date (no missing date; dd/mm/yyyy format) and in other column everyday rainfall (last 50 years; no blank).
I want to calculate what is the sum of monthly rainfall for every month of last 50 years in Matlab. Remember, there four types of month ending date: 30, 31, 28 and 29. Upto now I am able read the dates and rainfall value from excel file like below
filename = 'rainfalldate.xlsx';
% Extracts the data from each column of textData
[~,DateString ]= xlsread(filename,'A:A')
formatIn = 'dd/mm/yyyy';
DateVector = datevec(DateString,formatIn)
rainfall = xlsread(filename,'C:C');
what is the next step so that I can see every months of last fifty years rainfall sum?
I mean suppose July/1986 rainfall sum... Any new solutions?Code or loop base in Matlab 2014a
As #Daniel suggested, you could use accumarray for this.
Since you want the monthly rainfall for multiple years, you could combine year and month into one single variable, ym.
It is possible then to identify if a value belongs to both a determined year and month at once, and "tag" it using histc function. Values with similar "tags" are summed by the accumarray function.
As a bonus, you do not have to worry about the number of days in a month. Take a look at this example:
% Variables initialization
y=[2014 2014 2015 2015 2015 2014 2014 2015 2015];
m=[1 1 1 2 2 3 3 3 3]; % jan, feb and march
values = 1:9;
% Identifyier creation and index generation
ym = y*100+m;
[~,subs]=histc(ym,unique(ym));
% Sum
total = accumarray(subs',values);
The total variable is the monthly rainfall already sorted by year and month (yyyymm).

How to convert hourly rainfall data into daily rainfall

I have hourly rainfall and other data for long period. I would like to get daily values from these hourly data. My daily values should start from hour 1 to hour 24.
Year Month Day Hour Rain RH Temp
1976 1 1 1 3.4 60 16
1976 1 1 2 0 80 18
1976 1 1 3 NaN 50 18
First, get rid of NaN's, because e.g. 1+NaN=NaN, so it destroys any summation, average etc.
Then you can do for example simply this:
% M_hourly is a matrix with rows [Year Month Day Hour Rain RH Temp]
[H,W]=size(M_hourly);
for ii=1:24:H
Rain=M_hourly(ii:ii+23,5);
Rain_daily(ii)=sum(Rain);
end
You should prealocate the Rain_daily, cause it grows inside a loop.
I could be more helful, if you provide us with a more specific questions. I am just guessing what is the problem.

How to create a Scatter Plot chart in SSRS 2008?

I am trying to create a scatter plot chart in SSRS 2008 (not 2008 R2). Is this possible? I want to map military time of day for each day that an event occurs. So my data looks like:
Hour of Day Day of the Week
8 3
14 5
2 1
5 1
10 7
But right now it just sums the HOur of Day values. I want each of them as discreet values however. (Day of the week is 1-7 = Sunday-Saturday).
If this is possible, then how do I set this up?