Adding a Calculated Row in Tableau - tableau-api

I am displaying a table in Tableau for toys sales , I want to introduce a calculated row based on the previous row data. How can I do this in Tableau.
Toys type Sales in 2013 Sales in 2014
type1 10 15
type2 20 13
type3 30 28
type4 X/30 X/28

You can't specifically add one row to your database in Tableau. Calculated fields behave like fields, i.e. new columns.
If you explain what you're trying to achieve with this new row, we might be able to provide a solution. Adding a row, just for the sake of it, is not possible. You would need to manipulate your data source outside Tableau.
One thing you can do is create a calculated field to do that calculation for every row. Simple
X / [Toys type]
And X can be a number or a parameter

Related

Creating a calculated field in Tableau using 3 columns

Date1 Date2 Line Item Total
May10,2009 May9,2009 10 40
May9,2009 May10,2009 20 10
May9,2009 May8,2009 20 30
May8,2009 May11,2009 30 0
This is my Table in Tableau. I want to create a calculated field for last column. If Date2 value has a match in Date1 Column, the new value is equal to the sum of all values corresponding to that that in Line Item column. Is this possible in tableau using calculation or in some way? example: 'May9,2009' in Date2 COLUMN has two occurrences in Date1 Column. hence the two values in Line Item column (20+20) is added and new calculated field shows 40.
Someone please help.
Maybe you can try doing a Join with the same table. Creating new rows matching Date2 with Date1 from a duplicated of the same table. Something like this (Hoja and Hoja12 are the duplicated sheets, my excel is in spanish):
And then calculate de SUM of each row aggregated by Date2. Then you can get a table like this one:
*For [Line Item] itself I had to use average because the data exists in multiple rows due to the join made, but in everyone is the same value. If you want a cleaner way of that maybe you can try using LODs.
Hope this helps.
(Perhaps another approach for the whole problem could be using the LODs, but that means a better comprehension of that kind of expressions and this method was the first one I thought about)

Tableau Running Sum doesn't calculate for all months

My data looks like this:
Month Profit($)
June 2018 100
In my Tableau Grid, I have setup a Running Sum table calculation (RUNNING_SUM(SUM([Profit]))) to project the cumulative profit until Dec 2018.
It doesn't work if the above is the only row in the underlying data! (I want the 100 to carry over to all the future months until Dec).
But it does work, if there is are rows until Dec 2018 in the underlying data.
(I don't want to add any kind of dummy rows in my underlying data because this is a very simplified scenario and my actual scenario is way too complex to add dummy rows.)
For this we doesn't have the direct solution.
for a workaround I have created an excel sheet having the details of all the Months in a Year and connected it with the current data set as a Full Outer join.
It will give you the date field in the Dimension pane of Tableau, use that in the columns Pane and Click on Show Missing Values.
You will get the desired results.

Tableau - YTD, MTD as columns in text table

I'm trying to find a way to create a table like the one above, but instead of having columns of months I would like to have columns of MTD, QTD, YTD for all selected measure values. I created calculated fields on the [Date] field but when I try to use that it still splits the data in to separate columns of months and quarters... I'm using two data sources and they are linked on the [Date] field. If I try to put two of my calculated fields in the columns bar it just combines them like 'MTD/YTD'. How can I get them to display as separate columns?
I know this is strange because there will be overlapping data (everything in the MTD will also be in the QTD and the YTD).
I found a way to do this. I created a calculated field on the date field and assigned 'MTD' to all records from the last month. Then I assigned 'QTD' to all records from the start of the quarter to the day before the start date of the 'MTD' records. Then I assigned 'YTD' to all records from the start of the year to the day before the start of the 'QTD' records. (this way there are no overlapping records).
After that I just did a quick table calc to make each of them a 'running total' table (across).
I created parameters for the dates so the can easily be updated.

Unpivot data in Tableau Converting Rows to Columns

I have this data in Tableau:
KPI_NAME Value Date
------------------------
A 2 1-Jan
B 4 1-Jan
A 6 2-Jan
B 7 2-Jan
and I want it like this:
A B Date
------------------------
2 4 1-Jan
6 7 2-Jan
So I want it to convert each distinct value in the column KPI_NAME to a separate row, this can be done in the visualization part in Tableau but I want to do that in the data preparation because I want to use it in calculated field
Any help is appreciated.
Most tableau functionality is designed to consume more granular, flattened, and tidy data in the form of your first set. As such, the data prep functionality has a feature to unpivot column values into rows. I don't believe that reverse functionality is built into the data prep capability in the same way.
Not knowing your end use case, potentially a work around would be to:
Create a calculated field with an IF statement to return the value
when record is listed as A, otherwise return NULL.
Although you will still have the same number of records, you should be able to perform many of the calculations available with this type of data structure
Alternatively, you could perform you pivot outside of Tableau.

Select value in table in tableau

I am quite new to Tableau, so have patience with me :)
I have two tables,
Table one (T1) contains all my data with the first row being Year-Week, like 2014-01, 2014-02, and so on. Quick question regarding this, how do I make Tableau consider this as a date, and not as string?
T1 contains a lot of data that looks like this:
YearWeek Spend TV Movies
2014-01 5000 42 12
2014-02 4800 41 32
2014-03 2000 24 14
....
2015-24 7000 45 65
I have another table (T2) that contains information regarding some values I want to multiply with the T1 columns, T2 looks like:
NAME TV Movies
Weight 2 5
Response 6 3
Ad 7 2
Version 1 0
I want to create a calculated field (TVNEW) that takes the values from T1 of TV, and adds Response(TV) to it, and times it with the weight(TV),
So something like this:
(T1[TV]+T2[TV[Response]])*T2[TV[Weight]]
This looks like this for the rows:
(42+6)*2
(41+6)*2
(24+6)*2
...
(45+6)*2
So the calculation should take a specific value from T2, and do the calculation for each value in T1[TV]
Thanks in advance
The easy answer to your question will be: No, not natively.
What you want to do sounds like accessing a 2 dimensional array and that's not really the intention of Tableau. Additionally you have 2 completely independent tables without a common attribute to JOIN on. Tableau is just not meant to work that way.
I cannot think of a way to dynamically extract that value (I assume your example is just that, an example; and in your case you don't just use two values in the calculation, otherwise you could create 2 parameters that you can use in your calculated fields)
When I look at your tables it looks like you could transpose and join them that they ideally look like this: (Edit: Comment says transposing is not an option)
Medium Value YearWeek Spend
Movies 12 2014-01 5,000
Movies 32 2014-02 4,000
Movies 14 2014-03 2,000
Movies 65 2015-24 7,000
TV 42 2014-01 5,000
TV 41 2014-02 4,000
TV 24 2014-03 2,000
TV 45 2015-24 7,000
and
Medium Weight Response Ad Version
TV 2 6 7 1
Movies 5 3 2 0
Depending on the systems you work with you could already put it in one CSV or table so you wouldn't have to do a JOIN in Tableau.
Now you can create the first table natively in Tableau (from Version 9.0 onwards), if you open your data source, in the Data Source Preview choose the columns TV and Movies, click on the small triangle and then on Pivot. (At this point you can also choose the YearWeek column click on the triangle and Split to create a seperate field for Year and Week. You won't be able to assign the type date to it put that shouldn't give you any disadvantages.)
For the second table I can think of two possibilities:
you have access to a tool that can transpose your table (Excel can do that see: Convert matrix to 3-column table ('reverse pivot', 'unpivot', 'flatten', 'normalize') Once you have done that you can open it in Tableau and join the two tables on Medium
You could create calculated fields depending on the medium:
Field: Weight
CASE [Medium]
WHEN 'TV' THEN 2
WHEN 'Movies' THEN 5
END
And accordingly for Response, Ad and Version
Obviously that is only reasonable if you really just need a handfull of values.
Once this is done it's only a matter of creating a calculated field with
([Value]+[Response])*[Weight]
And this will calculate all the values for your table