Filtering a column per a maximum value to show on histogram - qliksense

I want to show on the histogram only the values from the 2nd major week.
Example: I have this table with "Week" and "feature_value". And week "6" is the 2nd major week.
Week feature_value
3 10,1
4 10,5
5 10,7
5 10,3
6 11,1
6 10,7
7 10,3
Basically What I want is this:
Week feature_value
6 11,1
6 10,7
I succeed doing it in qliksense table with this formula:
=Num(Aggr(distinct IF(max(Week,2),feature_value),feature_value))
But, when I use it on the histogram it appears "The chart is not displayed because it contains only undefined values."
See below the error:
Does anybody know how to solve it?

Related

Period To Date Median Over Time

I'm trying to calculate in Quicksight the median over time on a quarterly bases, so given these values:
Value
Date
1
01/01/2023
2
01/02/2023
3
01/02/2023
4
01/02/2023
5
01/03/2023
6
01/04/2023
7
01/04/2023
8
01/05/2023
Ideally I would like to get these values:
Value
Date
1
01/2023
2.5
02/2023
3
03/2023
6.5
04/2023
7
05/2023
There are some functions in Quicksight (like periodToDateAvgOverTime()) that perform this aggregation for other functions. Is there a way to calculate this with a custom formula or some work around?
You could use periodToDateAvgOverTime(median(value),....), or use the mediaIf(value,condition) and use the date as condition

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

Rolling N monthly average in Redshift with multiple entries per month

I would like to use Redshift's window aggregation functions to create an 'N' month rolling average of some data. The data will have multiple unique entries per any given month. If possible, I'd like to avoid first grouping by and averaging within months before performing rolling average as this is taking an average of an average and not ideal (as this post does: 3 Month Moving Average - Redshift SQL).
This is a sample dataset of just one account (there will be more than 1).
Quote Date Account. Value
3/24/2015 acme. 3
3/25/2015 acme. 7
4/1/2015 acme. 12
4/3/2015 acme. 17
5/15/2015 acme. 1
6/30/2015 acme. 3
7/30/2015 acme. 9
And this is what I would like the result to look like for a 3 month rolling average (for an example).
Quote_Date Account. Value Month 3M_Rolling_Average
3/24/2015 acme. 3 1 3
3/25/2015 acme. 7 1 5
4/1/2015 acme. 12 2 7.33
4/3/2015 acme. 17 2 9.75
5/15/2015 acme. 1 3 8
6/30/2015 acme. 3 4 8.25
7/30/2015 acme. 9 5 4.33
The code I have tried looks like this:
avg(Value) over (partition by Account order by Quote Date rows between 2 preceding and current row)
But, this only operates over the last 2 rows (and including current row) which would work if I had one unique value for each month but as stated, this is not the case. I am open to any kind of ranking solution or nested partitioning. Any help is greatly appreciated.
Since an average is just the sum() / count(), you just need to group by month but get the sum() and count(). Then use your lag to sum 3 months of sums and divide by the sum of 3 months of counts. You are correct that average of averages is not correct but if you carry the sums and counts things work.

How can I calculate the average between two text files based on matrixes?

I am fairly new to using MATLAB. I have two text files that have 500 rows x 100 columns and every one of it has a random value.
For example:
1 2 3 4 5
6 7 8 9 2
4 5 6 6 8
So my question is, corresponding to the row and column, how can I calculate the average of each particular field corresponding to the row and column?
For instance, at (1,1) in text1.txt is 20 and at (1,1) in text2.txt is 40. The average is 30 and I want to display this result in an another file at (1,1).
Many thanks.
assuming the files are named 'a' and 'b':
load a
load b
c=(a+b)/2;
save('c','c','-ascii');

Plot multiple data matlab [duplicate]

This question already has answers here:
Show two different plots in one plot
(2 answers)
Closed 8 years ago.
Good Morning, I have a problem with matlab plot.
I have generated sample of data that belong to different days; the data are the main posture of the human (labelled with 1,2,3,4).
Now I have 30 vector (one for each day) with the number of sample equals to the seconds of the day (about 86400 sample...). I have one posture for each second.
My aim is to plot the distribution of the sample during one month, in X axis I would have the days of the month (1,2,3.....30) and in the Y axis I would have the hour (sample/3600 I think).
How can I plot all the data in only one graph? I have two main problem:
I have 30 vector with different lenght (because I have generated the sample with random function) so the first step is to allineate the data I think because PLOT function needs vectors with the same lenght...
plot 30 days in the same plot, in order to evaluate the whole distribution of the posture in a month
A small example: day1 = [2222111333444] day2 = [22111333333444] day3 = [2221111133334444]. The input are sequences of postures (one sequence for day); now I need to obtain a plot with a "vertical representation" of these postures (on the x axis the days, on the y axis the hour of the day, for each hour I have about 3600 sample-one sample for second). With the command "hold on" no problem but I don't need to overlap the data but I need to place side by side the vector data
Andrea
It goes something like this, but of course,if you have 30 days and one entry per second you would need to use a matrix and sum the individual rows. Also, you don't need to make the vectors the same size, but then you have to use a different parameter for the x axis (Days) everytime.
day1=[2 2 2 2 1 1 1 1 3 3 3 4 4 4];
day2=[2 2 1 1 1 3 3 3 3 3 4 4 4 4];
day3=[2 2 2 1 1 1 1 3 4 4 4 4 4 4];
Days=1:3;
LayingTime=[sum(day1==1),sum(day2==1),sum(day3==1)];
SittingTime=[sum(day1==2),sum(day2==2),sum(day3==2)];
StandingTime=[sum(day1==3),sum(day2==3),sum(day3==3)];
RockingTime=[sum(day1==4),sum(day2==4),sum(day3==4)];
plot(Days,LayingTime,Days,SittingTime,Days,StandingTime,Days,RockingTime)
xlabel('Day')
ylabel('Hours of Activity')
legend('Hours Laying','Hours Sitting','Hours Standing','Hours Rocking')