Differencing a column in a data source - tableau-api

I have a text file with two columns: "date" and "cumulative value". I'd like to difference "cumulative value", as a calculated field in the data source.
I cannot even get a lag value:lookup([cumulative value],-1) produces an error.
Thank you.

There are two things you can do.
Create a new field with the following formula:
SUM([cumulative value])-LOOKUP(SUM([cumulative value]),-1)
Tableau requires an aggregation for you to use the LOOKUP function. Hence why I used the sum function. Then you could plot that against DAY(Date).
OR
Plot DAY(Date) against SUM(cumulative value), then right click SUM(cumulative value), click Quick Table Calculation, and then Difference. This can only be used/done in plots though.

Related

How to divide an Aggregate and Sum function

I am working in Tableau and trying to create a formula that will return me the value of each customer that walks into a store by dividing Net Sales / Traffic. When I try to combine the two separate formulas, it gives me the following error: Cannot mix aggregate and non-aggregate arguments with this function. The two functions I created that I'm trying to divide are:
SOT = (SUM([Sales Net])-SUM([Sales Gcard Net]))/SUM([Traffic Perday]) and SOT Goal
When I look at it in Tableau, it's stating that SOT is an aggregate function. How do I work around this to be able to get
SOT / SOT Goal
Aggregate variables are values that are calculated in the view, and depend on the level of aggregation in Tableau. e.g. sum(Sales) will show different values in Tableau if it’s next to a Region dimension, or if it’s next to a Category dimension.
In order to avoid the errors you can use many solutions. My favorite is indeed LOD expressions. In your view, though I do not have required sample data and therefore, I cannot try my hands on different possibilities here, I suggest that this should work-
SOT = ({SUM([Sales Net])}-{SUM([Sales Gcard Net])})/{SUM([Traffic Perday])}
Do remember that this solution will over-ride your filters and if you are using filters you have to add all those to Context.
EDIT
While trying different possibilities remember these things...
{SUM([Sales])} will sum the sales over entire data and {} i.e. curly braces wrapped around the sum function will cause to return the value as non-aggregate. In other words, this will work as LOD and if you'll add this field to view, the sum of entire sales will be shown against each row.
{FIXED [DIMENSION NAME] : sum([Sales])} will sum sales separately for each Dimension value. Fixed statement (LOD) again returns the value as non-aggregate value. if you'll add this field to view, the sum of entire sales for that dimension will be shown against each dimension.

Get average value of each (Sub) column

i would like to calculate the average of values of each "main" column, as shown in the picture (named as bundling column). Each bundling(main) column has 1 to N "sub columns" (which are values for a certain datetime). The bundling itself is variable, it changes for different filters.
How can i reference to these sub columns to get the sum/count and average of these? I thought of using the "Window average" function but i don't have an idea how to define the start/end offset parameters. Not sure if window average is the correct option.
Thank you very much
A level of detail (LOD) calculation will allow you to control at what level the aggregation occurs.
{INCLUDE [Agg(Bundling)]: AVG([Agg(Error Select)]}

Calculated Field error involving aggregates

Problem: The sheet has a calculated field named 'Average % Delta' and the field is required at date level.
On using the average function to figure out the average value of the calculated field, it throws aenter image description heren error. (an aggregate function cannot be aggregated further)
Is there any way around this error?
The calculations should hold for multiple selections in the filter too.
Similar error repeats while trying to find the standard deviation too.
link to tableau workbook :
https://drive.google.com/open?id=1jtpy9fu0UvinMz-56dI5_je8m7AZ-jnp

Tableau: Plot percentage of binary column

Simplified example: column of 'measure' data is binary 0's and 1's. The sum of the column (all the 1's summed) is 3948. The length of the column is 4567. 3948 is 86% of 4567. How do I create a bar chart showing this percentage. All I can get is a bar adding up to 100%.
I've tried absolutely everything in the percentage of dropdown, calculated fields, online tutorials, etc.
Two approaches:
Right click on your measure field on whichever shelf you placed it. Choose Quick Table Calc -> Percentage of Total. Experiment with different settings for "Compute Using" and read about addressing and partitioning of table calculations to learn how to specify percent of "what".
Or create a calculated field specific to your problem defined as below:
sum(int([my measure field] = 1)) / count(1)
Be sure to set the default number format for your calculated field to a percentage, by right clicking on it in the data pane (left margin) and revising the default properties
Note, the second calculation works because the INT() function converts True to 1 and False to 0, which is useful in several contexts.
You can go about this using the following method
Add 'measure' to Columns and make it a Discrete Dimension
Add SUM(Number of Records) to Rows. This should give you the bar chart you need.
This would help achieve what you are looking to do. For more customization and a better look for the graph you are looking to build in Tableau.
Add 'measure' to the colour legend and make it a Discrete Dimension.
Add SUM(Number of Records) as a Label and do a '% of Total' quick table calculation.

Get 2 max date in Tableau

My requirement is to get the second max date available in report and filter the data set on this.
I tried something like this:
datediff('day',dt,max(dt))=1
Referred to this link
any help?
You're going to need Tableau 9.0 for this. Basically because any calculation you do on Tableau depends on the level of detail you have on the worksheet (the dimensions you put in there). So datediff('day',dt,max(dt))=1 won't work. First because you're mixing aggregated fields (max(dt)) with non-aggreagated (dt). Second, because the aggregation depends on the dimensions in the workfield.
But Tableau 9.0 has a new awesome feature, called Level of Detail calculations. It allows you to perform calculations in the level of detail you choose, depending not on the dimensions on the sheet. It is also calculated BEFORE any calculation on the worksheet (just after context filters).
Now to the answer. First I'll figure out what is the max(dt). Let's call it max_dt
{ FIXED : MAX(dt) }
This will calculated the maximum of dt in all your database
Now to get the second max, you can go like this:
{ FIXED : MAX(IF dt != max_dt
THEN dt
END)
}
This will calculated the maximum of dt, ignoring those who are equal to max_dt (that is the true max(dt)). Therefore, the second max.
Take a look on those LOD calculations. They were just released, I'm having tons of fun with them right now
If the view has date dimension
The easy way to do this,is to create a calculated Last()=1
then filter off the records that evaluate to TRUE