Aggregating from multiple columns in Tableau - tableau-api

I have a table that looks like:
id aff1 aff2 aff3 value
1 a x b 5
2 b c x 4
3 a b g 1
I would like to aggregate the aff columns to calculate the sum of "value" for each aff. For example, the above gives:
aff sum
a 6
b 10
c 4
g 1
x 9
Ideally, I'd like to do this directly in tableau without remaking the table by unfolding it along all the aff columns.

You can use Tableau’s inbuilt pivot method as below, without reshaping in source .
CTRL Select all 3 dimensions you want to merge , and click on pivot .
You will get your new reshaped data as below, delete other columns :
Finally build your view.
I hope this answers . Rest other options for the above results include JOIN at DB level, or creating multiple calculated fields for each attribute value which are not scalable.

Related

generate serial number in decreasing order given a variable in tableau

would like to find out the syntax in tableau, given column number, trying to generate rows for number in decreasing order down to 0.
Below is an example of what I'm trying to do
BEFORE
ID
NUMBER
A
4
B
5
AFTER
ID
NUMBER
A
4
A
3
A
2
A
1
B
5
B
4
B
3
B
2
B
1
If your Tableau version supports, try using ROWNUMBER with order by. Something like this:
{ ORDERBY [Your column]:ROW_NUMBER()}

Turn 1 row into multiple rows in Azure Data Flows

I have a dataset along the lines of:
Account No
P01_Ind
P02_Ind
P03_Ind
1
Y
Y
N
2
Y
N
Y
3
N
Y
N
Is there a way of adding a transformation in Azure Data Flows so that each row would turn into 1 or more rows depending on these indicator columns? In this example, my dataset would become:
Account No
Indicator
1
P01
1
P02
2
P01
2
P03
3
P02
I looked at Unpivot but I couldn't see how this would work with this data. Note that this transformed dataset would undergo further transforms and wouldn't be sinked after this step. Any tips gratefully received. Thanks.
You can use ConditionalSplit transformation then add Indicator column to each condition by 'DerivedColumn' transformation. Finally, use Union and Select transformation to meet your need.(You can sort output of Select transformation if you need.)
Steps:
create a dataset and its data like your provided.
use ConditionalSplit transformation to split data to different stream.
add Indicator column to each stream.
union three stream
use 'Select' transformation to delete P01_Ind,P02_Ind,P03_Ind column.
sort output of Select transformation.
Data preview of 'Sort':
This is as simple as doing a unpivot which will get you the rows with 'Y'/'N' as another column and then filtering the rest out for values of 'N'.
You will get
1 P01_Ind Y
2 P02_Ind Y
3 P03_Ind N
.....
It is scalable next time you have 10 instead of 3 columns.

How to add 2 Attributes one after another in MSTR?

I am new to MSTR and trying to build a new Dossier and i got stuck on the below issue.
I have 2 attributes and 1 metric in my dataset and Attribute 1 has data A, B & C and Attribute 2 has data X, Y, Z. i want dashboard to look like this
Attribute Metric
A 1
B 2
C 3
X 4
Y 5
Z 6
When i create my result look like below.
Attribute1 Attribute2 Metric
A X 1
B y 2
C z 3
Please help.
Can you reformat your results - Attribute Metric A 1 B 2 C 3 X 4 Y 5 Z 6
I think you mean you want to view metrics for the elements for both the attributes appended one below the other.
I'd suggest you create a consolidation / custom group object and add all elements from both your attributes.
And use this consolidation / custom group instead of the attribute on your report.

KDB/Q : What is Vector operation?

I am learning KDB+ and Q programming and read about the following statement -
"select performs vector operations on column lists". What does Vector operation mean here? Could somebody please explain with an example? Also, How its faster than standard SQL?
A vector operation is an operation that takes one or more vectors and produces another vector. For example + in q is a vector operation:
q)a:1 2 3
q)b:10 20 30
q)a + b
11 22 33
If a and b are columns in a table, you can perform vector operations on them in a select statement. Continuing with the previous example, let's put a and b vectors in a table as columns:
q)([]a;b)
a b
----
1 10
2 20
3 30
Now,
q)select c:a + b from ([]a;b)
c
--
11
22
33
The select statement performed the same a+b vector addition, but took input and returned output as table columns.
How its faster than standard SQL?
"Standard" SQL implementations typically store data row by row. In a table with many columns the first element of a column and its second element can be separated in memory by the data from other columns. Modern computers operate most efficiently when the data is stored contiguously. In kdb+, this is achieved by storing tables column by column.
A vector is a list of atoms of the same type. Some examples:
2 3 4 5 / int
"A fine, clear day" / char
`ibm`goog`aapl`ibm`msft / symbol
2017.01 2017.02 2017.03m / month
Kdb+ stores and handles vectors very efficiently. Q operators – not just +-*% but e.g. mcount, ratios, prds – are optimised for vectors.
These operators can be even more efficient when vectors have attributes, such as u (no repeated items) and s (items are in ascending order).
When table columns are vectors, those same efficiencies are available. These efficiencies are not available to standard SQL, which views tables as unordered sets of rows.
Being column-oriented, kdb+ can splay large tables, storing each column as a separate file, which reduces file I/O when selecting from large tables.
The sentence means when you refer to a specific column of a table with a column label, it is resolved into the whole column list, rather than each element of it, and any operations on it shall be understood as list operations.
q)show t: flip `a`b!(til 3;10*til 3)
a b
----
0 0
1 10
2 20
q)select x: count a, y: type b from t
x y
---
3 7
q)type t[`b]
7h
q)type first t[`b]
-7h
count a in the above q-sql is equivalent to count t[`a] which is count 0 1 2 = 3. The same goes to type b; the positive return value 7 means b is a list rather than an atom: http://code.kx.com/q/ref/datatypes/#primitive-datatypes

Comparing, matching and combining columns of data

I need some help matching data and combining it. I currently have four columns of data in an Excel sheet, similar to the following:
Column: 1 2 3 4
U 3 A 0
W 6 B 0
R 1 C 0
T 9 D 0
... ... ... ...
Column two is a data value that corresponds to the letter in column one. What I need to do is compare column 3 with column 1 and whenever it matches copy the corresponding value from column 2 to column 4.
You might ask why don't I do this manually ? I have a spreadsheet with around 100,000 rows so this really isn't an option!
I do have access to MATLAB and have the information imported, if this would be more easily completed within that environment, please let me know.
As mentioned by #bla:
a formula similar to =IF(A1=C1,B1,0)
should serve (Excel).