Tableau percentage change of same measure - tableau-api

I have added a very simple example Tableau here: https://drive.google.com/file/d/1yG7EdIrKrTklhWOEoAmM4xwSbFZpOTvf/view?usp=sharing
In this example what I would like to achieve is to have a % change column which shows the % change.
I've tried using Quick table calculations but I cannot find any calculation that allows me to get the % change. I've also tried to use a calculated field with IF statements, but the calculation was returning blank cell.
P.S.
This is part of a more complex example in this thread: https://community.tableau.com/message/753038#753038
I have followed the answer in the link above and I was able to get to the point where I have the data showing up in two separate columns "Current Year" and "Prior Year".
But then I'm stuck on the supposedly easy step of simply calculating the % change between those two columns.

I was able to solve this issue by right clicking on the measure and selecting "Add Table Calculation".
Then I choose Calculation Type = "Percent Difference From", computing using = "Table (across)" and finally relative to = "Previous"

Related

How to copy data from a 1 x 1 double timeseries to a 1 D Lookup Table in Matlab

I have been asked to look at a Matlab project. I'll link sceenshots to clarify the problem. I need to create a 1 D Lookup table with the data from a 1 x 1 double timeseries from another model that has been supplied. One problem is that there are a lot of data points (12500). Is it possible to copy these points across without having to drag the mouse down over the whole 12500 points? Someone has actually tried this dragging the mouse over all the points method and said it didn't work anyway, but I don't really want to try it myself, as it would be way to cumbersome for my liking, even if it did work.
Here is an example of what the 1 x 1 double timeseries looks like (just using 5 points instead of 12500 for simplicity's sake):
Here is the model with the 1D look up table highlighted in blue at the left:
Here is what the 1-D lookup table looks like when opened:
Any insight appreciated.
I've worked out how to copy the data from the timeseries table (actually from the input to this, which is a 1 x 1 struct), but he problem is that the values have no commas between them and the 1-D lookup table requires commas.
Note that the problem has now been solved using Excel, although not by the method I was trying to make work in the question. An answer has been posted which may work, but I'm not sure if i will go to the trouble of attempting to implement it or not at this stage. However, if need be and all being well, I will either do that or delete the question.
You can import a look-up table object (Simulink.LookupTable-object) from both, the MATLAB workspace or directly from Excel.
If you want to automate it, it basically comes down to these two points:
"
Open the model containing the lookup table block and in the Modeling tab, select Model Settings.
In the Model Properties dialog box, in the Callbacks tab, click PostLoadFcn callback in the model callbacks list.
... the next time you open the model, Simulink® invokes the callback and imports the data.
"
After a little thought I feel like the answer is actually fairly trivial: it just can't be done. The input field of the look up table just can't hold 12500 points, most of which have 9 or so decimal places, so there's no way to do this.
This isn't to say there's no way to put the data into the model: this can be done using Excel.

Reset Parameter Values to original value read from Excel sheet

I have parameters that's read its values from Excel spread sheet (Picture 1). However, I have a method that reduce the parameter values by x% (picture 2). I could reverse the calculation method in picture 2 which not going to help much.
Question:
I want to create a bottom that reset the parameters values to its original excel values. I am not sure how to create such a method? Appreciate any hints or ideas.
First of all, this is very redundant code you code put into a for-loop (select all your params, right click, then create a collection of Doubles).
Then, you can easily loop across all these again and simply divide them by interNo, getting you the original values.

Converting from datenum back to actual time

Ok, so I've been messing with what should be a simple problem. I'm trying to plot an numerical array (double) vs. the associated time stamp (cell) with the format of the DD-MM-YY HH:MM:SS (for example: 13-Mar-15 07:23:10).
I'm able to plot a single set using datetime(time stamp). Due to the data set it outputs the nice HH:MM on the x-axis. Very nice.
Now in order to plot 2 sets of values on the same graph, I've found that Matlab doesn't like to use the date_time twice for the x-axis, so then I go to the infamous datenum function, which is able to plot both on the same graph. However, it's in the serial value of time and it jacks with my plot sizing (i.e. the x-axis doesn't autosize).
With what should be a simple problem has actually caused me days scouring the internet trying to reconvert it back to my beloved HH:MM after converting the "time stamp" into the serial time.
I don't think that a code sample or data set should be necessary for example purposes. (but can provide if needed)
I've tried to use the datetick function, but can't get seem to get it working.
The trick with datenum and datetick is to set limits and tick positions before you call datetick, then make sure it doesn't redo them.
So, after plotting your two sets of data against the datenums it would go something like:
step = 1/24; % for hourly - adjust to preference
ticks = datenum('mystarttime'):step:datenum('myendtime')
set(gca,'XTick',ticks)
datetick('x','HH:MM','keepticks','keeplimits')
I work a lot with time series and most often I have to plot my data versus time/date.
Since Matlab never gave me a definitively convenient solution, for many years now I work this way:
I defined once and for all a Matlab shortcut (in the matlab shortcut toolbar):
containing the following code:
xticktemp = get(gca,'Xtick') ;
ticklabel = {datestr(xticktemp(1)) datestr(xticktemp(2:end),15) } ;
set(gca,'Xticklabel',ticklabel)
clear xticktemp ticklabel
I convert all my times with datenum and use this format for working (or posix time when more convenient, but it's another story), calculating and plotting. When I need to now exactly the time of an event in a human readable format, I press the shortcut and I obtain something like:
Of course there are 2 major limitations with this method:
This does not control the steps of the ticks (it just replicate what Matlab initially set)
You have to re-click your shortcut to refresh the tick labels everytime you zoom or pan the figure
For these reasons, when I need to finalize figure for presentation to others I won't use this trick and define my ticks exactly like I want them, but when you are simply working away, this shortcut has saved me hours (may be even days?) of fiddling around over the last 10 years ....

How to forward test and plot?

Have received a lot of help. Will look for some more. Learning a lot by just going through the code.
I have thus far:
Loaded an xlsx file using xlsread function.
After this calculated the correlation coeff. Assigned it a variable(?).
Then used(Thanks #Robert P.):
BUYx = x(find(APC < -2.9079,1,'first'))
SELLy = y(find(APC < -2.9079,1,'first'))
BUYy = y(find(APC > 0.44,1,'first'))
SELLx = x(find(APC > 0.44,1,'first'))
To get the first value meeting a particular condition.
Now I want to forward test from where the first value is received till another condition is met. At the same time I would like to make a plot the results.
I am just wondering where to start looking to code/try this.
Please point me in the direction of the functions required. I think it has to loop through all the elements after receiving entry. Not sure which is the right way to go about it.
Thanks
Context:
I am trying to test a StatsArbitrage strategy. I was using excel for the work but I can't seem to get the right functionality.
Basically, when we have an entry(any set of the BUY SELL) I want the system to automatically start calculating Profit/Loss from the next data point and give an output to a new variable. Then I would plot it.
Then search for new entry and again start Profit/Loss calculation.

where do i put a formula in matlab

I have no matlab or mathematical experience but i would like to do the following :
convert an excel file to a tab delimited file and open this in matlab organized in the following way:
every row is a new subject
first colum is name of subject
other 8 columns are the parameters for each subject
I would like to run a growthfunction on each subject and obtain the following results
the maximum velocity and corresponding growth and time
the minimum velocity before the maximum velocity is reached and corresponding time and growth
the maximum growth (the function nears an asymptot)
-This is the code that I would use
tmin=0;
tmax=20;
dt=1
t=tmin:dt:tmax;
y = m1.*(1-1./(1+(m2.*(t+m8)).^m5+(m3.*(t+m8)).^m6+(m4.*(t+m8)).^m7));
dy=diff(y)./dt;
max(dy);
min(dy);
imax=find(dy==max(dy))+1;
imin=find(dy==min(dy))+1;
t(imax);
t(imin);
y(imax);
y(imin);
y(20);
Where do i put this code so that it knows that m1 to m8 are corresponding to the different columns in my file? how do i link these?
How can i make sure that the output of each subject appears in a column in my tab delimited file (like excel)
In brief what I would like to do:
have a file with on every row a new subject and column 2-9 are the values of the parameters m1 to m8. Run the formula so that in column 9 i will have the maximum velocity, in 10 the minimum velocity and so one...
Can anyone help me out
Thanks
[~,~,rawData]=xlsread('yourExcelSheet.xlsx')
SubjectNames=rawData(:,1) % I think () is better here than { }, may have to switch this up.
Data=cell2mat(rawData(:,2:9)) % convert the last 8 columns (2 to 9) to a matrix of type double
%This ^^ also assumes there are no headers in excel, if there are headers, it would be %rawData(2:end,2:9) instead of what I have above
m1=Data(:,2)
m2=Data(:,3)
% etc. etc.
m8=Data(:,9)
alternatively, if you can get over the messiness, substitute "Data(:,2)" in your equation instead of m1, it will give you a tiny speedup
Disclaimer: I just wrote all this off the top of my head, if it errors, hopefully its just something small, otherwise let me know.
you can just import the data by double clicking the xls file. A dialog should appear. Select the data range that you want to import.
you can then simply state untitled(:,1) = m1 etc.