Row level average calculation tableau - average

I need to calculate average in tableau..one equation was sum(var A* varB)/sum(varB)..I have converted it into row level equation as avg((varAvarB)/varB) and it is working fine.but now I have another equation i.e sum(varAvarB)/total(sum(varB)).could some one help me how to convert this into row level average calculation.

This is a classic scenario where you can leverage Level of Detail expressions in Tableau
read here: https://help.tableau.com/current/pro/desktop/en-us/calculations_calculatedfields_lod_overview.htm
Your expressions would emerge like : AVG([{FIXED [Segment]], [Category]] : SUM([Sales]])}])
You will have greater control over row-level operations using LoD
Please read the link and try it

Related

Is it possible to access forecast results in calculated measure?

I am trying to find time series outlier using Tableau forecast. I need to compare the actual value with the 95% confidence level in forecast results to determine if it is an outlier.
I understand I can view the forecast results on the chart. But I want to use the forecast results in calculated measure. Is there any way to do it? I cannot find any Tableau functions to retrieve the forecast results.
Xuefei. Doesn't look like there is a way currently, at least going by their help page - https://help.tableau.com/v2019.1/pro/desktop/en-us/forecast_options.htm. If you haven't already considered this - integration with R is easy and that way you could just model it in R (accounting for additive/multiplicative, trend/cyclicity/seasonality) and access the forecast values from R. Integration with Python is also supposed to be easy, although I haven't tried it myself.
Example of code in Tableau to incorporate R code for linear regression (this is the formula for the calc field in Tableau)
SCRIPT_REAL("
fv=log(.arg1)
fpri=.arg2
fit=lm(fv~fpri)
exp(fit$fitted)",SUM([Impressions]),SUM([CPM]))

Tableau calculation: I am trying to calculate the percentage of running sum but am unable to create a calculation

I am trying to calculate number of customers which represent 80% of the profit so that I can use it in a calculated field which I can use in a reference line.
This is what I wrote
IIF(RUNNING_SUM([Profit])= (0.8*SUM([Profit])),
COUNTD([Customer Name]),0)
but it gives me error saying
"All fields must be constant or aggregate when using table calculation functions"
The logic is to "Count distinct number of customers which represent 80% of running total profits"
This is meant for a pareto chart, so the values are already sorted in descending order for it to work.
How do I create such calculated field which would give me number of top customers which will represent 80% of the profits?
Let me know if more clarifications are needed.
I think you are looking for a Pareto Chart. This might help:
http://www.theinformationlab.co.uk/2014/08/27/pareto-charts-tableau/
I would leverage the power of Table Calculations, where you can first do running total of profit and then simply calculate percentage of total.
Here is the link to step-by-step tutorial in Tableau10 for Pareto Analysis (80/20 rule):
https://www.tableau.com/learn/tutorials/on-demand/pareto-charts?signin=15df68b66e703787258911e79db040a7.
Hope this helps.

Tableau CPC calculation

I have a problem with calculating CPC in Tableau.
I have the cost and the number of the click but Tableau is not calculating the right CPC. the formula I used : [Cost]/[Click]
I attached two tables in this request. first shows the table which I calculated all KPIs in Zeppelin. the second the calculation in Tableau.
The whole data set has many null and 0 values, but it is the same data set used in zeppelin.
May I ask for help,how to solve this issue?
The result of CPC is not correct in Tableau.
Helena,
the issue is that Tableau is using aggregate functions when you add measures, and in this case of CPC calculation, it's not correct.
Tableau is doing [cost]/[click] division (on row-level) and then simply averages all those numbers (you are basically calculating an average of an already average number).
What you are after is a bit different and you have to fix the math to make sure all costs are aggregated first and then divided by sum of all clicks, so:
SUM([cost]) / SUM([clicks])
This will give you the correct and mathematically sound numbers.
Hope this helps.
SUM([cost]) / SUM([clicks]) will resolve the issue

Using tableau to compute entropy from a estimated probability distribution

I have the following situation: after sniffing multiple packets from a WLAN, I consider the random variable X with values given by the protocol number and probabilities given by the number of packets with that protocol number over the total of the packets (that is, I poorly estimate the probability that a given protocol occurs on the network).
This gives me something like this:
These values are calculated by using
COUNT([Protocol]) / TOTAL(COUNT([Protocol]))
Now, however, I want to convert these values into information content (which is just applying -LOG(, 2) to the expression above) and add a line showing the entropy of the "source".
If I were to do this, an easy way would be to just do:
SUM(EXP((-1) * x) * x)
Where x is -LOG(,2) of the first expression. However, Tableau complains about this being a double aggregate. Is there any other way to calculate this?
Change SUM to WINDOW_SUM to create a table calculation, and set "compute using" for that calculation to your protocol number field
If you want to understand more, study how table calculations work. In a nutshell, the sum() calculation is performed by the external data source or database in response to the query sent by Tableau. Then the aggregated query result is returned to Tableau as a summary table. Table calcs such as Window_Sum() operate on that summary table.
The "compute using" directive instructs Tableau on how to partition the summary table; that is to define the scope of the window used to compute Window_Sum()
I find the following sentence very useful for understanding why we are interested in "Entropy in Tableau":
"The basic intuition behind information theory is that learning that an unlikely event has occurred is more informative than learning that a likely even has occurred."
Page 73, Deep Learning, 2016

Different Aggregation calculations of a measure using two dimensions in Tableau

It is a Tableau 8.3 Desktop Edition question.
I am trying to aggregate data using two different dimensions. So, I want to aggregate twice: first I want to sum over all the rows and then multiply the results in a cummulative manner (so I can build a graph). How do I do that? Ok, too vague, here follow some more details:
I have a set of historical data. The columns are the date, the rows are the categories.
Easy part: I would like to sum all the rows.
Hard part: Given this those summations I want to build a graph that for each date it shows the product of all the summations from the earlier date till this date.
In another words:
Take the sum of all rows, call it x_i, where i is the date.
For each date i find y_i such that y_i = x_0 * x_1 * ... * x_i (if there is missing data, consider it to be one)
Then show a line graph for the y values versus the date.
I have searched for a solution for this and tried to figure it out by myself, but failed.
Thank you very much for your time and help :)
You need n calculated fields (number of columns you have), and manually do the calculation you need:
y_i = sum(field0)*sum(field1)
Basically because you cannot iterate on columns. For tableau, each column represent a different dimension or measure. So it won't consider that there is a logic order among them, meaning, it won't assume that column A comes before column B. It will assume A and B are different things.
Tableau works better with tables organized as databases. So if you have year columns, you should reorganize your data, eliminate all those columns and create a single field called 'Date', which will identify the value of your measure for that date. Yes, you will have less columns but far more rows. But Tableau works better this way (for very good reasons).
Tableau 9.0 allows you to do that directly. I only watched a demo (it was launched yesterday), but I understand that now there is an option to selected those columns (in the Data Connection tab) and convert them to a database format.
With that done, you can use a PREVIOUS_VALUE function to help you. I'm not with Tableau right now. As soon as I get to it I'll update this with the final answer . Unless you take the lead and discover yourself before that ;)