Sort Column header based on row value, and show as columns - sorting

We have sheet with column names and values in the cells below.
We like to have a list of the names and the value next to it ordered.
example.
A
B
C
D
E
1
John
Mary
Tom
Grace
2
3
4
5
2
and we would like the same data below which looks like...
A
B
1
Tom
5
2
Mary
4
3
John
3
4
Grace
2
Any ideas? Thanks

use:
=SORT(TRANSPOSE(A1:D2), 2, )
or:
=SORT(TRANSPOSE({A1:D1; A4:D4}), 2, )

SUGGESTION
Perhaps you can try this way:
=QUERY(TRANSPOSE(A1:D2),"SELECT * order by Col2 DESC")
Sample Sheet
Reference
TRANSPOSE
QUERY

Related

Distinct on two columns with same data type

In my game application I have a combats table:
id player_one_id player_two_id
---- --------------- ---------------
1 1 2
2 1 3
3 3 4
4 4 1
Now I need to know hoy many unique users played the game. How can I apply distinct, count on both columns player_one_id and player_two_id?
Many thanks.
By using union you can get unique distinct value.
$playerone = DB::table("combats")
->select("combats.player_one_id");
$playertwo = DB::table("combats")
->select("combats.player_two_id")
->union($playerone)
->count();

Insert empty row which shows total when Item number get change

In my report, there is a table which shows Item number, Employee name, and Hours.
Item Number Employee Hrs
1 ABC 2
1 DEF 1
2 ABC 3
2 XYZ 4
I want to show one empty row below as a separator when Item number get change. In that row want to show the total number of hours. Like below.
Item Number Employee Hrs
1 ABC 2
1 DEF 1
Total 3
2 ABC 3
2 XYZ 4
Total 7
Thanks, Bhushan the link was helpful. Link: https://learn.microsoft.com/en-us/sql/reporting-services/lesson-6-adding-grouping-and-totals-reporting-services?view=sql-server-2017.
I changed the report design by adding grouping. Also showing sum after each group.

PIG: Filter hive table by previous table result

I need to query one HIVE table and filter the other table with one column of the previous one.
Example:
A = LOAD 'db.table1' USING org.apache.hive.hcatalog.pig.HCatLoader();
filterA = filter A by (id=='123');
B = LOAD 'db.table2' USING org.apache.hive.hcatalog.pig.HCatLoader();
//the problem is here. filterA has many rows. I need to apply filter for each of the row.
filterB = filter B by (id==filterA.id);
Data in A:
tabid id dept location
1 1 IS SJ
2 4 CS SF
3 5 EC MD
Data in B:
tabid id name address
1 4 john 123 S AVE
2 5 jane 456 N BLVD
3 9 nick 789 GREAT LAKE DR
Expected Result:
tabid id name address
1 4 john 123 S AVE
2 5 jane 456 N BLVD
As asked in the comment, it sounds like what you're looking for is a join. Sorry if I misunderstood your question.
A = LOAD 'db.table1' USING org.apache.hive.hcatalog.pig.HCatLoader();
B = LOAD 'db.table2' USING org.apache.hive.hcatalog.pig.HCatLoader();
C = JOIN A by id, B by id;

Multiple tablix for report

i have the following scenario i am trying to simplify using Visual Studio and Microsoft BI Stack (SSRS).
I have a Dataset as follows.
Year Employee Sales
1 A 5,000,000
2 A 7,500,000
3 A 6,500,000
1 B 3,500,000
2 B 5,000,000
3 B 8,000,000
1 C 5,750,000
2 C 7,500,000
3 C 6,500,000
1 D 4,500,000
2 D 5,500,000
3 D 6,100,000
I am trying to create a report whereby, a single report would span 3 Tablix inside report body when run to display as follows.
Year 1
Year Employee Sales
1 A 5,000,000
1 B 3,500,000
1 C 5,750,000
1 D 4,500,000
Year 2
Year Employee Sales
2 A 7,500,000
2 B 5,000,000
2 C 7,500,000
2 D 5,500,000
Year 3
Year Employee Sales
3 A 6,500,000
3 B 8,000,000
3 C 6,500,000
3 D 6,100,000
Now i know i could replicate the Tablix 3 times in the report body, but that would be a bad idea when it comes to maintaining this report.
In the effort to avoid repeating myself, is there a way to loop the Tablix (N Times) in SSRS where condition would be the Year column (values 1, 2, 3.....)?
Following are the steps :-
Insert a List. Group it by the Year.
Put your tablix inside the list.
This should do it.
What you want to do is to NEST two tables.
First, create your table that gives you all the results like you want.
Then create a second table with one column and one row and Group it by your Year field.
Place your first table in the second table's so that it repeats for each year.

KDB+ / Q Syntax optimizations to oneliners

I am definitly a q-mortal. I would even say a q-baby. Well I have some question how to put together my code from separate lines to a one-liner. I guess there is a way more elegant solution than mine.
How to write the following statements in one line:
q)t1:(3#3)?\:`8
q)t1[;0]:`abc
In this table creation, how can I add another column which I have as list (like with the command ([]id:id_list;data:data_list;.....)). Till now I am creating another table and doing an inner join on them. I guess that's not very efficient:
`id xkey update id:i from flip (`row1`row2!(1 2;3 4))
For the 1st one you may do:
q)`abc,/:(3#2)?\:`8
abc jognjhck cihanjhp
abc hkpblald aeajbddp
abc blmjhgah ooeiogdj
For 2nd one you may treat the table as a dictionary:
q)tb
row1 row2
---------
1 3
2 4
q)(tb`id): 5 6
q)tb
row1 row2 id
------------
1 3 5
2 4 6
Two options:-
Create a 3*2 matrix of random symbols and append `abc in front.
q)`abc,/:(3#2)?\:`8
Or create 3*3 matrix of random symbols and use functional form of amend to update the first column. This is a more generic approach.
q).[(3#3)?\:`8;(::;0);:;`abc]
I don't see any problem with using just update statement.
q)c:1 2
q)t
row1 row2
---------
1 3
2 4
q)update newCol:c from `t
`t
q)t
row1 row2 newCol
----------------
1 3 1
2 4 2

Resources