Spotfire Average over a column - average

I have a question related to Spotfire. I have a table
And what I need to get is an Average of the rate (Operational Costs/Production) grouped by Region. Mathematically it looks like this for Europe: ((Costs A 2017 + Costs B 2017)/(Production A 2017 + Production B 2017) + (Costs A 2018 + Costs B 2018)/(Production A 2018 + Production B 2018) + (Costs A 2019 + Costs B 2019)/(Production A 2019 + Production B 2019)) / 3
and do the same for Asia. So basically, I need to calculate the rate for the Region and find an average over the years. can't figure out, how to do this.

#user2538414- I would suggest you to add a pivot transformation to your original table to make it more readable and easy to work with.
Please check the below post which explains how to pivot and unpivot data tables.
Spotfire - How to group multiple columns under a single column in data table visualization
Transformed Table:
To this transformed table you can add a calculated column with the custom expression below to compute Rate (Costs/Production) by Region and year.
Sum([Costs]) over (intersect([Region],[Year])) / Sum([Production]) over (intersect([Region],[Year]))
You can further refine this custom expression to suit your requirement.
Final output table:

Related

Tableau - Name Rank, by State / Year / Gender

I have a data set downloaded from the Social Security website. The data is in the form below, and contains the popularity (i.e., as defined by Count) of names, by gender, year and state:
State Gender Year Name Count First Letter
AK F 1910 Anna 10 A
AK F 1910 Annie 12 A
AK F 1911 Annie 6 A
AK F 1912 Alice 5 A
AK M 1912 Wilbur 7 W
AK M 1912 Thomas 7 T
Within Tableau, I'd like to Top X names by each of these categories (or all if not filters are applied). However, when I use a Top filter in a visualization, the underlying data produced by the filter is the form:
For example, I need the first ranked name, and be able to use filters to see how that changes by year, gender, and state. I'm thinking this might be accomplished by an LOD expression, but not sure where to start.
You can achieve this without needing a LOD calculation. Simply change your filters from standard blue dimension filters to be context filters. To do this simply right click on the filter when it is in the filter pane and click "Add to Context". The filter will be shown as grey. Now all ranks will be calculated after filters have been apllied
Why does this work? It is to do with the Order of Operations in Tableau. A calculation such as rank is a table calculation. As the name implies the calculation is processed on the entire data table before dimension filters are applied. However, when something is a context filter it creates temporary tables which are then used to calculate table cals.
Find out more here: https://www.google.com.au/search?q=order+of+operations+tableau&oq=order+of+operations+tableau&aqs=chrome..69i57j0j69i65j0j69i65j0.3475j0j7&sourceid=chrome&ie=UTF-8

How to plot two sets of points on one scatter plot in Tableau

I have a data set that includes employee name (rows) and # of calls in 2016, 2016 revenue, # of calls in 2017, and 2017 revenue for each employee. Is there a way to plot (employee's 2016 calls, employee's 2016 revenue) AND (employee's 2017 calls, employee's 2017 revenue) on one scatter plot in Tableau?
I've tried to plot 2016 calls and 2017 calls (columns) on a dual axis and 2016 revenue and 2017 revenue (rows) on a dual axis, but it ends up plotting all possible (X,Y) combinations, when there should only be two points per employee (2016 data and 2017 data).
Alternatively, is there a way to plot a line through each of the 2016 points if I've calculated the slopes of the lines I want to use?
If you want one mark for each combination of employee and year, the simplest solution is to shape your data source to have one data row for each combination of employee and year.
So revise your data source to have the following columns:
Employee
Year
Calls
Revenue
Then try Employee on Detail, Year on color (as a dimension), SUM(Calls) on Columns and Sum(Revenue) on Rows
If you don't want to reshape you data as a preprocessing step, you can accomplish the same goal in the Data Source editing panel by UNIONing the original source with itself, add a Year field based on the Table Name field and creating calculated fields to have versions of Calls and Revenue that include the values only for that one year.

How to calculate within a factor in Tableau

Apologies if this question is trivially easy, I'm still learning Tableau.
I have data where the variables Set and Subset are arranged by week (W1 to W52) and by Source (A or B). So if I put Week into Rows and create the calculated fields
SUM(Set)
SUM(Subset)
Rate = {INCLUDE Source: SUM(Subset) / SUM(Set)}
I get data that look like this:
Week SUM(Set) SUM(Subset) Rate
A B A B A B
W1 1234 123 567 56 45.95% 45.53%
So far, so good. But what I really want is the percentage difference between Rate(A) and Rate(B) by week:
Diff = (Rate.A - Rate.B) / Rate.B
I could do this in a second if I were using Excel or R, but I can't seem to figure out how Tableau does it. Help?
There's a built in table calculation "Percent Difference" , you can deploy it using compute using Table across and relative to previous. For that you need to have continuous measures.
Something like this will be the calculation-:
(ZN(SUM([Quantity])) - LOOKUP(ZN(SUM([Quantity])), -1)) / ABS(LOOKUP(ZN(SUM([Quantity])), -1))
Create two different for "Set" & "Subset"

How to create a crosstable showing descriptive statistics in PostgreSQL?

I have a table contains data of year and value. I'd like to create a cross table with all the year as column headings and calculate descriptive statistics in the rows.
For instance, I'd like to calculate the mean and median value for year 2005, 2006, and 2007 separately and put them in the following table format.
2005 2006 2007
Median
Mean
To calculate the median and mean for year 2005, the code would be:
SELECT avg(vallue),percentile_cont(0.5) WITHIN GROUP (ORDER BY value)
FROM tablename WHERE year=2005;
but I don't know how to turn it into a table
in postgres "crosstab" is extension for pivot tables
for median I used this aggregate function and it was quite effective (fast and precise)

Interactive Report - aggregate sum of multiple columns from one table multiply by values from another Table

I have a challenge in Oracle Apex - I would to sum multiple columns to give 3 extra rows namely points, Score, %score. There are more columns but I'm only choosing a few for now.
Below is an example structure of my data:
Town | Sector | Outside| Inside |Available|Price
Roy-----Formal----0----------0----------1------0
Kobus --Formal----0 ---------0--------- 1------0
Wika ---Formal----0----------0--------- 1------0
Mevo----Formal----1----------1----------1------0
Hoch----Formal----1----------1----------1------1
Points------------2----------2----------5------1
Score------------10---------10---------10------10
%score-----------20---------20---------50------10
Each column has a constant weighting (which serves as a factor and it can change depending on the areas). In this case, the weighting for the areas are in the first row of the sector Formal:
Sector |Outside| Inside |Available|Price
Formal----1----------1 ----------1-----1
Informal--1----------0 ----------2-----1
I tried using the aggregate sum function in apex but it wont work because I need the factor in the other table. This is where my challenge began.
To compute the rows below the report
points = sum per column * weighting factor per column
Score = sum of no of shops visited (in this case its 5) * weighting factor per column
% score = points/Score * 100
The report should display as described above. With the new computed rows below.
I kindly ask anyone to assist me with this challenge as I have tried searching for solutions but haven't come across any.
Thanks a lot for your support in advance!!