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

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.

Related

Spotfire: Empty values on x-axis

Spotfire question: I have a data table with monthly data that is visualized in a bar chart. I however also want to visualize the information in quarters, by showing the latest month of the quarter in the format '20Q1, 20Q2, etc.'. (So I don't want to use standard 'date format'.)
My idea was to create an additional column that is filled for March, June, Sep, Dec and empty for the other months. Then with a document property, the user can select to either view the data in months or in quarters (i.e. the last month of the quarter).
So far so good, my data now looks like this:
Month
Value
YearQuarter
Jan-20
100
Feb-20
200
Mar-20
400
20Q1
Apr-20
125
May-20
101
Jun-20
300
20Q2
The problem now is that when I visualize the data with YearQuarter on the x-axis, it also shows all the (empty) values in a bucket. See below. How to solve this? Note that the x-axis has a custom expression "<$esc(${Granularity})>", where Granularity is a document property to determine what column to pick.
Did you try limiting your data with whatever expression you have put in x axis.
Thanks

Spotfire Average over a column

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:

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)

How to Calculate YTD (Jan to prev month) in a single column in tableau

Original post - https://community.tableau.com/thread/206909
I have a report in which I have sales per month in the column and commodities in the row. The data show actual sales and future estimates for each month.
Need to calculate Year-To-Date (YTD) total for 2016 (from Jan to Previous month) and have it in a single column at the end of the actual values.
I already created a calculated field - YTD
IF
YEAR([DATE]) = YEAR(NOW())
AND
MONTH([DATE])< MONTH(NOW())
THEN
[VALUE/UNIT]
ELSE
0
END
But when I add to the view, it creates a another section for YTD with sum for each month till April.
Can someone please help me in how to achieve this in Tableau?
There are couple of ways to achieve this view in Tableau
1. To create calculated field for each Month and YTD and add measure names in Row & Measure values in Text
2. Make union of 2 queries - one that select all the correct values & second that have YTD calculation in month column. Then use pivot it

How do I achieve a multi-series line chart in Crystal Reports?

This relates to my How do I achieve a pivot report in Crystal Reports for Visual Studio? The data is the same, but they want a line chart as well.
So, my data is {datetime}, {car-id}. The X -axis of the chart must show the hour of {datetime}, the Y axis the number of cars that entered the park at that hour, and I must have seven data series, lines, one for each day of the week. So, e.g. the x/y point on the green line shows that on Wednesday, at hour x, y cars entered the car park.
Common sense tells me that I can kludge this by transforming the data source so that each day has its own column in a table, a table like this:
DateTime
WeekDay
CarCount
Yet the Crystal line chart doesn't seem to support more than one column, so there must be a different and better way of doing this. The weekday is part of {datetime} after all.
How can I achieve this chart? I am a rank amateur at charting, and Crystal's idiosyncrasies really aggravate my lack of skills and experience in this area.
It's not obvious how to get multiple series to show up properly.
First, create a formula that will extract the day of week from the datetime: dayofweek({datetime}) and then create another that will extract just the hour: hour({datetime}).
From there, insert a chart from scratch and make the following settings in the Chart Expert
Select "Line" under the Type tab
Under the Data tab, select "On change of" and select your {#HourOfDay} formula first. This will create each hour as a point on the X-axis.
In that same spot, also insert the {#DayofWeek} formula. This will create a new line
for each day of the week. This is, in my opinion, the non-obvious part.
Finally, to pick your Y-axis values,
select {car-id} where it says "Show value(s)". It should default to
the count summary of that field.
(Note: in the screenshot below, you would just replace {Customer.Customer_Name} with {car-id}
I had this issue for 5 years and finally solved it. I have a XY chart with multiple series.
Everything needs to be in a formula.
The graph should be in the report header section of a subreport. The sub report generates the X Y data like this:
Series X Y
Ser1 2020 1
Ser1 2021 2
Ser2 2020 0
Ser2 2021 1
For me I have as series "Energy" ie 6, 9, 12 etc.
Then I have a date/time and a measurement.
On change of (Energy formula)
Show Values
#1 DateTime (convert this to int ie 2000.9 for 9/2000) - dont summerize
#2 Measurement (number) - dont' summerize
Then you can do the color highlighter to capture your series (6 is red etc).
The legend won't work - can't figure out that yet.