Switching values between columns IF - powerquery

I have a various columns with numeric data in them, and I was wondering if I can somehow switch values between columns IF a condition is met - if value in columna A is equal to 0 and value in column B is deifferent that 0, then I would like to swich those values so that column A has a value from B and vice versa.
I was trying to do that with Table.ReplaceValue but the problem is, that once I replace a value in column A with that from column B, my condition won't be met during next replacement.
Example:
If a Table looks like that:
PART NO
COLUMN A
COLUMN B
1
120
0
2
0
80
3
130
140
I'd like it to change like this:
PART NO
COLUMN A
COLUMN B
1
120
0
2
80
0
3
130
140

Add column .. custom column... Column A.1
= if (insert your test here) then [COLUMN B] else [COLUMN A]
Add column .. custom column... Column B.1
= if [COLUMN A] = [COLUMN A.1] then [COLUMN B] else [COLUMN A]
then right click and remove original two columns, and rename these

Related

How to convert a table in a matrix in KNIME?

Is it possible and if so, how to convert a table to a matrix?
My output table is structured as follows:
rowid user item value
0 x A 10
1 x B 15
2 x C 0
3 y A 12
4 y B 17
5 y C 25
My goal is to create a matrix in the following form:
rowid A B C
x 10 15 0
y 12 17 25
Use a Pivoting node with the following settings:
Group column(s) user
Pivot column(s) item
Manual Aggregation > Column value
Advanced Settings > Column name: Pivot name
You can leave the Aggregation set to First.
Connect the Pivot table output to a RowID node with settings:
Replace RowID with… checked
New RowID column user
Remove selected column checked

Subtract Duplicates between 2 Arrays

Say I have column A which contains 20 unique alphabetical names, and column B which contains 5 alphabetical names. I want to write a formula that counts the unique names in column A and subtracts matching names that exist in column B. For example, if I have A2 = Tom, A3 = Mike, A4 = Ben, A5 = Sam; B2 = Ben then it takes 4 unique names from column A and subtracts the 1 matching name in column B to equal 3. I also want this formula to ignore blank cells across both column ranges.
=COUNTA(IFERROR(UNIQUE(FILTER(A:A, NOT(COUNTIF(B:B, A:A)), LEN(A:A)))))

Inserting Data using join in Hive

Hi I have two Tables and after Join I want to Insert Data into Third Tables. Problem I am facing is I have to create multiple records based on the value of Join.
Table 1
A B
-------
1 X
2 y
3 x
Table 2
A C
-------
1 Y
2 N
3 Y
I need to join Table 1 and Table 2 on Column A and Based on value of Column C in Table 2 I need to insert Records in Table 3
Rule
If Column C value is 'Y' then insert 3 Records as 'Red','Green','Blue'
If Column C value is 'N then insert 2 records as 'White','Black'
So Result should be
Table 3
A D
-----------
1 Red
1 Green
1 Blue
2 White
2 Black
3 Red
3 Green
3 Blue
Can you let me know how to achieve this using hiveql ? Thanks
You can create a third table Color
Table Color
------------------
Flag Color
Y Red
Y Blue
Y Green
N White
N Black
Now you can join them easily
Select * from Table1 T1
JOIN Table2 T2
ON T1.A = T2.C
JOIN COLOR C
ON T2.C = C.Flag

How to match a value from a table upto a particular position in oracle?

I have to write a query to match values in two tables, Table A and Table B , Table A is havingvalues in column XYZ as "91517181","915171812", i want to check if its exist in table B or not , but in table B, the value in column ABC is "9151718", but in another column in table B it is having its match length as "10". Which means it is upto "9151718XXX".
So i have to write a query where value from table A should match with value in table B, because in table B, the value is upto 10 characters.
Kindly help...
I think that you need something like this:
table a: table b:
xyz x y
---------- ---------- ---
9151718 9151718 10
91517181 91360 5
913601
select a.xyz, rpad(xyz, b.y, 'x') result, b.x pattern, b.y len
from a
left join b on a.xyz like b.x||'%' and length(a.xyz)<=b.y
xyz result pattern len
---------- ---------- ---------- ---
9151718 9151718xxx 9151718 10
91517181 91517181xx 9151718 10
913601 <- not matched
I think something like that:
select * from a where
exists(select 'x' from b where substr(xyz, 1, y) = x)
x - value in b
y - length in b

Aggregation Operation in Kettle / Pentaho

I'm trying to do an aggregate operation between some columns from an Excel file input. I have the following case:
Column 1 Column 2 Column 3
X $15 A
X $20 A
Y $1 B
Y $1 B
Y $3 C
And i want to achieve this aggregation operation:
Column 1 Column 2 Column 3
X $35 A
Y $2 B
Y $3 C
As you see, the Column 1 and 3 are the criteria for doing the aggregation operation, in this case, i want to get the sum of the column 2.
Is there any way to do this in Pentaho Data Integration? I've tried with "Join Rows" and "Join Rows (As a cartesian product)", but, i have no results.
Please look to Group By step. It should allow you to group by Column 1 and Column 3 and sum Column 2.

Resources