Tableau: calculated field after data is reshaped - tableau-api

I'm trying to wrap my head around how to created a calculated field in Tableau that is calculated after the source data is pivoted. My source data is "long" i.e. normalized and looks like this:
+---------+---------+-------+
| Company | Measure | Value |
+---------+---------+-------+
| A | Sales | 100 |
+---------+---------+-------+
| A | Exp | -10 |
+---------+---------+-------+
| B | Sales | 200 |
+---------+---------+-------+
| B | Exp | -30 |
+---------+---------+-------+
(Actually every company would have more than two records, but this is simplified)
What I'd like to get out is the following where Net is calculated as Sales + (2 * Exp).
+---------+---------+-------+-------+
| Company | Sales | Exp | Net |
+---------+---------+-------+-------+
| A | 100 | -10 | 80 |
+---------+---------+-------+-------+
| B | 200 | -30 | 140 |
+---------+---------+-------+-------+
I can get the following by simply having Company as my row and Measure as my column and then sum(Value):
+---------+---------+-------+
| Company | Sales | Exp |
+---------+---------+-------+
| A | 100 | -10 |
+---------+---------+-------+
| B | 200 | -30 |
+---------+---------+-------+
But how do I calculate an additional column based on the result of pivoting Measure?

Does this get you what you need?
The crux is creating calculated fields for Exp and Sales like this:
Exp =
if [Measure] = "Exp" then [Value] end
Sales =
if [Measure] = "Sales" then [Value] end
Those become measures you can use as the columns.

Related

how to show absolute and percentage of total (pane) in text table format in tableau

I'm new in Tableau, I have data like this
month | gender | sales | quantity |
Jan-2022 | male/female | integer | integer |
my goal is to create a table shown below in tableau.
|----------------------------------------------------------------------------|
| | Jan-2022 |
| | male | female |
|metrics | absolute | composition | absolute | composition |
|-----------------------------------------------------------------------------
|sales | 1000 | 33% | 2000 | 66% |
|quantity | 50 | 20% | 200 | 80% |
|----------------------------------------------------------------------------|
to create the composition for each metrics i use the percentage of total then choose compute using -> pane (across). but i have no idea how to put the percentage side by side in the table.

How to get non-aggregated measures?

I calculate my metrics with SQL and publish the resulting table to Tableau Server. Afterward, use this data source to create charts and dashboards.
For one analysis, I already calculated the measures per day with SQL. When I use the resulting table in Tableau, it aggregates these measures to SUM by default. However, I don't want to have SUM or AVG of the average or SUM of the Percentiles.
What I want is the result when I don't select date dimension and not GROUP BY date in SQL as attached below.
Here is the query:
SELECT
-- date,
COUNT(DISTINCT id) AS count_of_id,
AVG(timediff_in_sec) AS avg_timediff,
PERCENTILE_CONT(0.25) WITHIN GROUP(ORDER BY timediff_in_sec) AS percentile_25,
PERCENTILE_CONT(0.50) WITHIN GROUP(ORDER BY timediff_in_sec) AS percentile_50
FROM
(
--subquery
) AS t1
-- GROUP BY date
Here are the first 10 rows of the resulting table:
+------------+--------------+-------------+---------------+---------------+
| date | avg_timediff | count_of_id | percentile_25 | percentile_50 |
+------------+--------------+-------------+---------------+---------------+
| 10/06/2020 | 61,65186364 | 22 | 8,5765 | 13,3015 |
| 11/06/2020 | 127,2913333 | 3 | 15,6045 | 17,494 |
| 12/06/2020 | 306,0348214 | 28 | 12,2565 | 17,629 |
| 13/06/2020 | 13,2664 | 5 | 11,944 | 13,862 |
| 14/06/2020 | 16,728 | 7 | 14,021 | 17,187 |
| 15/06/2020 | 398,6424595 | 37 | 11,893 | 19,271 |
| 16/06/2020 | 293,6925152 | 33 | 12,527 | 17,134 |
| 17/06/2020 | 155,6554286 | 21 | 13,452 | 16,715 |
| 18/06/2020 | 383,8101429 | 7 | 266,048 | 493,722 |
+------------+--------------+-------------+---------------+---------------+
How can I achieve the desired output above?
Drag them all into the dimensions list, then they will be static dimensions. For your use you could also just drag the Date field to Rows. Aggregating 1 value, which you have for each date, returns the same value whatever the aggregation type.

LibreOffice calc formula: find the value for a given data based on known data

I have LibreOffice Calc spreadsheet with table that calculates cost for two services. I want calculate cost of service #2 based on known data. The known data are rates (0,80 and 0,68: its permanent) and total incl.VAT 21%. Variable data in column C (unknown): C2 always equal to C3. Based on known data, I want split "Total incl. VAT" amount into a two separate parts, service #1 and service #2 cost. In particular, I want know the 'service #2' amount with VAT. (D3 + VAT) Can someone show formula how to make this?
+---+------------+---------------+-----------------+----------+-----------------+
| | A | B | C | D | E |
+---+------------+---------------+-----------------+----------+-----------------+
| 1 | services | Rate (eur/m3) | volume, m3 | Sum(eur) | service #2 cost |
| 2 | service #1 | 0,80 | 71,00 | 56,80 | |
| 3 | service #2 | 0,68 | 71,00 | 48,28 | |
| 4 | | | Subtotal: | 105,08 | |
| 5 | | | VAT 21% | 22,07 | |
| 6 | | | Total incl. VAT | 127,15 | D3 value + VAT |
+---+------------+---------------+-----------------+----------+-----------------+

Tableau - Operations between two tables from different sources and different granularity

I'm using tableau Desktop V9.1.13 with two tables from different data sources (one comes from Bigquery and the other from a postgresql DB) and I want to perform a multiplication between two columns of these tables. The first table has one row for a single transaction and the other has one row for each currency available in the database. I've tried blending and create a calculated field but the last always throws an error. The first table looks like this:
+----------------+--------+----------+
| transaction-id | Value | Currency |
+----------------+--------+----------+
| 123-abc | 120 | BRL |
+----------------+--------+----------+
| 556-fds | 100 | PEN |
+----------------+--------+----------+
| 456-cde | 120000 | COP |
+----------------+--------+----------+
| 789-fgr | 100 | MXN |
+----------------+--------+----------+
And the other table
+----------+--------------+
| Currency | Value in USD |
+----------+--------------+
| COP | 0.0003 |
+----------+--------------+
| BRL | 0.3169 |
+----------+--------------+
| PEN | 0.2958 |
+----------+--------------+
| MXN | 0.0539 |
+----------+--------------+
Now I want to generate a new column called Value_USD that is the product of the transaction amount with the value of its currency.
+----------------+--------+----------+-----------+
| transaction-id | Value | Currency | Value_USD |
+----------------+--------+----------+-----------+
| 123-abc | 120 | BRL | 38 |
+----------------+--------+----------+-----------+
| 556-fds | 100 | PEN | 29.58|
+----------------+--------+----------+-----------+
| 456-cde | 120000 | COP | 40 |
+----------------+--------+----------+-----------+
| 789-fgr | 100 | MXN | 5.39 |
+----------------+--------+----------+-----------+

Subtract fields of a column - Tableau

I would like to subtract promoters and detractors in Tableau by creating a new column. Thanks for all the help!
Customer Type Table (I would like to create the NPS field as shown below):
+---------+------------+----------+-----------+--------------+
| Quarter | Detractors | Passives | Promoters | NPS |
+---------+------------+----------+-----------+--------------+
| Q1 15 | 40.56 | 23.56 | 35.79 | =35.79-40.56 |
| ... | ... | ... | ... | ... |
+---------+------------+----------+-----------+--------------+
Simply create a calculated field (called NPS):
[Promoters] - [Detractors]
This will add a new field to every row of your partition called NPS.
Check out the Tableau online help on calculated fields - this is a skill well worth learning.
I understand the OPs question. The data comes in like this:
+---------+---------------+------+
| Quarter | Customer Type | Score|
+---------+------------+---------+
| Q1 15 | Detractors | 25 |
| Q1 15 | Promoters | 32 |
| Q1 15 | Passives | 45 |
| Q1 15 | Detractors | 17 |
| Q1 15 | Detractors | 28 |
| ... | ... | ... |
+---------+------------+---------+
And when brought into Tableau, the [Customer Type] field is put in the Column shelf and this arranges the data like the table below. The OP wants to calculate the [NPS] column (Promoters - Detractors).
+---------+------------+----------+-----------+--------------+
| Quarter | Detractors | Passives | Promoters | NPS |
+---------+------------+----------+-----------+--------------+
| Q1 15 | 40.56 | 23.56 | 35.79 | =35.79-40.56 |
| ... | ... | ... | ... | ... |
+---------+------------+----------+-----------+--------------+
I hope this clarifies. I am stuck with a similar situation (I want a column that shows the difference between 2015 and 2016):
+---------+-------+-------+------------+
| Measure | 2015 | 2016 | Difference |
+---------+---------------+------------+
| # Hires | 100 | 115 | 15 |
| # Terms | 9 | 6 | 3 |
+---------+---------------+------------+
I believe the steps are similar. I hope someone can help.