Tableau rotating data table - tableau-api

I have a dataset that looks like this in Tableau.
Name Subject Grade
Mina Math 28
English 92
Science 10
Bill Math 19
English 10
Science 38
Kay Math 39
English 92
Science 83
I need the data to look like this
Name Math English Science
Mina 28 92 10
Bill 19 10 38
Kay 39 92 83
How can I do this in Tableau? I am assuming I need to create a calculated field. Just not sure how to approach this as I am a beginner.

As Alex Blakemore suggested, you could pivot your entire dataset in the data source page itself, but I am assuming the first view you have is a Worksheet with Name, Subject, Grade fields in columns of the worksheet, and you would like to present your data as in the second view without modifying your data source.
It's possible by creating three calculated fields:
Math:
IF [Subject] = "Math" THEN [Grade] END
English:
IF [Subject] = "English" THEN [Grade] END
Science:
IF [Subject] = "Science" THEN [Grade] END
Now try dragging Name, Math, English and Science fields into the columns of the Tableau Worksheet and you should be able to get what you need without actually pivoting your data source itself. Hope this helps!

Related

Are there any instances where a negative time type could give unexpected results?

Are there any instances where a negative time type could give unexpected results if used for specific purposes? When time deltas are calculated between negative time values and non-negative time values for example, there do not appear to be any issues.
time
val
00:00:31.384
-0.3170017
00:06:00.139
0.9033492
00:07:01.099
-0.7661049
Then, for the purpose of a window join later over a 10-min window
win:00:10:00;
winForJoin: (neg win;00:00:00) +\:(exec time from data);
first[winForJoin] gives -00:09:28.616 -00:03:59.861 -00:02:58.901
winForJoin[1]-winForJoin[0] gives 10 minutes as expected
If I understand correctly, you're asking how would a window join behave if the opening interval was a negative time? (due to the interval subtraction taking the values into negative territory, relative to 00:00).
The simple answer is that it won't behave any differently than if the times were numbers, but in practice you may see results you don't expect depending on how your table is set up and what you're trying to achieve.
Taking the example in the official wiki as a starting point: https://code.kx.com/q/ref/wj/
q)t:([]sym:3#`ibm;time:10:01:01 10:01:04 10:01:08;price:100 101 105)
q)a:101 103 103 104 104 107 108 107 108
q)b:98 99 102 103 103 104 106 106 107
q)q:([]sym:`ibm; time:10:01:01+til 9; ask:a; bid:b)
q)f:`sym`time
q)w:-2 1+\:t.time
/add volume too so it's easier to follow:
q)s:908 360 522 257 858 585 90 683 90;
q)update size:s from `q
/add an alternative range which has negative starting time
q)w2:(-11:00;1)+\:t.time
The window join takes all rows in q whose times are between the pairs of time ranges:
q)q[`time]within/:flip w
110000000b
011110000b
000001111b
Under the covers it's asking: are these positive numbers (the quote times) in between those two positive numbers (the window range). There's no reason it can't also ask: are these positive numbers in between this negative number and this positive number
q)q[`time]within/:flip w2
110000000b
111110000b
111111111b
You'll notice that all of them are greater than the negative time - meaning that it will include all rows from the beginning of the q table, up until the end time of that pair. This can be considered expected behaviour - if your start time is negative you must mean "from the beginning of time" - aka, all rows from the beginning of the table.
Comparing sum of size shows how the results differ:
q)wj[w;f;t;(q;(sum;`size))]
sym time price size
-----------------------
ibm 10:01:01 100 1268
ibm 10:01:04 101 1997
ibm 10:01:08 105 1448
q)wj[w2;f;t;(q;(sum;`size))]
sym time price size
-----------------------
ibm 10:01:01 100 1268
ibm 10:01:04 101 2905
ibm 10:01:08 105 4353
Finally - where it might get complicated.....it depends on what "negative" time means in your table. If you're at 00:00 (midnight) and you subtract 10 minutes, are you trying to access data from 23:50 the day before? Or does 00:00 represent the starting time (row zero) of your table? If you're trying to access 23:50 from the day before then you will have problems because 23:50 is NOT in between your negative start time and your positive end time, e.g:
q)23:50 within(-00:58:59;10:01:02)
0b
Again this all depends on how your data looks and what you're trying to do

Tableau stacked and side-by-side bar chart on column aggregation

I have a data set like this
Name Occupation Payment Principal Interest
Amy Nurse 100 90 15
Becky Teacher 80 100 20
Catherine Nurse 90 75 15
John Engineer 90 80 12
Tom Teacher 120 100 20
... ... ... ... ...
I'd like to create side-by-side(Payment) stacked chart:
Row: Occupations
Column1 : stacked(Sum of Interest and Sum of LP Principal) by occupation
Column2 : Only Sum of LP Payment by occupation
Can anyone give me hint how to make it?
Your data is not in the correct format for the required chart and you need to do some data prep.
Pivot all three measure fields from the data source page.
create a calculation to define the column for each data type
Build the chart as below and hide the header for column field.
One approach that avoids reshaping your data is to use the measure names and measure values placeholder fields to create the stacked bar chart.
See below

Identify missing Dimension Value in Tableau

I have student name, subject and marks in three columns. My use case is to identify the subject in which selected student has not enrolled. I can do it very easily using SQL but requirement is to identify it in Tableau. I have tried LOD's and Traditional Filters but it's of no help.
**Sample Data**-
Name Subject Marks
Rob A 90
Rob B 95
Rob C 98
Ted B 86
Ted D 70
**Desired Output**-
Name Subject
Rob D
Ted A
Ted C
If graphical solutions are also an option, you can print the Subjects on e.g. the X axis, and the Student Names on the Y axis. Then, set the marks type to e.g. text and display the Number of Records in each cell. This way, you should get a matrix of all Subject vs. all Students, with 0 or 1 in each cell (intersection).

select every 3rd participate from a list and make and average in matlab

I got 3 lists with grades ranging from 0-100 represting 3 different tests.
each list has an equal number of indxes (represting participates).
For example- the 1st indexes in the lists- list1,list2 and list3, are the grades of the first particiapte in the 3 different tests.
I need to make a new group (named group1) that select evey 3rd participate, starting from the first, and than calculate the avarage of this group scores.
i'll appriciate any help!!
Hopefully instead of three 'lists' you are actually using a 3 column matrix for this? e.g.
testScores = [20 48 13;
85 90 93;
54 50 56;
76 80 45
...]
From here it is trivial to select every third participant:
testScores(1:3:end, :)
and then to find the mean:
mean(testScores(1:3:end,:),2)

Report Builder - Average of field if another field = X

I'm just beginning with Report Builder and I am trying to get an average of the value of one field if another field equals a number.
Example:
A table that contains a series of book reviews by different reviewers identified by number:
Reviewer Score
1 95
2 85
3 77
3 99
1 87
What I want is to get a reviewer's overall average score. So i would like to get an average of all scores filtering out the other reviewers.
I have been at this for a couple hours now and I don't think I am even close...
=Avg(iif(reviewer="1",score,Nothing))
I have used this successfully in my report.