Transpose Excel Row Data into columns based on Unique Identifier - excel

I have excel table in below format.
Sr. No. Column 1 (X) Column 2(Y) Column 3(Z)
1 X Y Z
2 Y Z
3 Y
4 X Y
5 X
I want to tranpose it in following format in MS Excel.
Sr. No. Value
1 X
1 Y
1 Z
2 Y
2 Z
3 Y
4 X
4 Y
5 X
Actual data contains more than 30 columns which needs to be transposed into 2 columns.
Please guide me.

Select complete table data and then name it as SourceData using
Formula>Name Manager
Now implement following formula for getting first column:
=INDEX(SourceData,CEILING(ROWS($A$1:A1)/(COLUMNS(SourceData)-1),1),1)
And for second column:
=INDEX(SourceData,CEILING(ROWS($A$1:A1)/(COLUMNS(SourceData)-1),1),MOD(ROWS($A$1:A1)-1,COLUMNS(SourceData)-1)+2)
Copy and paste special values and then delete blanks / zeroes.
You will get result as required.

If you were using other databases, there might be a formal unpivot operator/function available. But in MySQL, this is not a possibility. However, one approach which should work here would be to just take a union of the three columns:
SELECT 1 AS sr_no, col1 AS value WHERE col1 IS NOT NULL
UNION ALL
SELECT 2, col2 WHERE col2 IS NOT NULL
UNION ALL
SELECT 3, col3 WHERE col3 IS NOT NULL
ORDER BY sr_no;

Related

List result of lookup A in B, B in C without helper column

I have 2 tables:
Table1 containing Customer & Part#
Table2 containing Part# & Type
(The actual data lists are larger)
Table1 (Customer & Part#) & Table3 (Helper):
Customer
Part#
Helper
A
1
X
B
2
Y
C
3
X
A
4
Y
A
5
X
A
5
X
A
2
Y
Table2:
Part#
Type
1
X
2
Y
3
X
4
Y
5
X
Desired result for combination of customer A and Type X:
Part#
1
5
5
These being the 3 results of part numbers in Table1 that are Customer A and the lookup of the Part# results in Type X (see also Helper column).
I'm able to retrieve the results by creating the helper column as shown in the example data, however I want to skip this column and solve it in one go. But I don't know if that's even possible.
I was thinking about something in this direction.. =INDEX (Table1[Part'#],IF(Table1[Customer]="A",ROW(Table1[Customer]))
..but there I get stuck. I think I can pickup from there with IF, ISNUMBER, SEARCH but my head errors there.
Does anybody know a way to skip the helper column for this?
PS I have office365, but FILTER is not yet released by company rules (unfortunately).
PS I prefer a formula solution, but VBA is allowed when necessary
Here is a formula solution for Excel version 2010 to 2019
In I3, formula copied down :
=IFERROR(INDEX(B:B,AGGREGATE(15,6,ROW(A$3:A$9)/(VLOOKUP(N(IF({1},B$3:B$9)),D$3:E$7,2,0)=H$3)/(A$3:A$10=G$3),ROW(A1))),"")

turn rows into columns and coping and keeping the same index infrond of all previous together columns

the inverse of
Transpose columns to rows keeping first 3 columns the same
turn:
id col1 col2 col3
1 A B
2 X Y Z
into:
id
1 A
1 B
2 X
2 Y
2 Z
I'm trying unpivot() but from the solution, I cited I need to use .unstack() ?

Conditional formatting in Excel for totals

X Y Z
1 5 0
1 4 0
1 9 1
2 5 0
2 4 0
2 **8** 1
Basically, I have an excel table with 3 variables. X is an group variable, Y is a value, and Z is a dummy variable that indicates if the Y value in that row is a total or not. Is there any way to write the conditional formatting rule so that discrepancies between SUM(Y) over the same X, and the supposed total are highlighted?
In the table above, The third row with X would not be marked because 5+4=9, so there is no discrepancy, but the 6th row would be marked because 5+4!=8, so that one should be highlighter. I appreciate your help!
Use SUMIFS();
Assuming your data starts in A1
=AND(SUMIFS($B:$B,$A:$A,$A1,$C:$C,0)<>$B1,$C1=1)
Apply it to B:B.

Grouping rows together in excel if they are scattered based on a field

Lets say we have an excel with customerid and amount . If i sort the excel on amount my customers will be scattered. So i want to achieve sort and then group same customers amount tohether maintaining that sort.
If i have below
Row 1 . X 200
Row 2. Y 245
Row 3. Z 45
Row 4. Y 456
Row 5. Z 23
Row 6. T 5678
I want output as :
T 5678
Y 456
Y 245
X 200
Z 45
Z 23
When you select a single column and perform a sort, it disregards values from other columns. So, before sorting your Excel sheet, you need to select the entire sheet:
After that, choose "sort" from the menu, and select sort by column A and then by column B:
Result:
Please see the sorted data on Column B (modified data for Z as 999).
Sorted on Column B
Now below is the result i want to achieve.That is , after sorted on Column B , the rows should re-arrange such that the customers data gets together. Result as below, we can see that 2nd last row z 999 had to be moved , putting below Z 23.
Final Result

Sum max values in a column based on two other columns

I have three columns and I want the sum of the maximum values in Col2 for each category in Col1 where Col3 is equal to x.
I am not able to add a 4th column to obtain the max first.
Col1 Col2 Col3
a 3 x
b 2 x
c 2 x
a 1 x
b 3 x
c 1 y
a 2 y
b 1 y
c 3 y
In this example the answer I am looking for is 8:
3 for a,
plus 3 for b,
plus 2 for c.
How can I do this?
You could try this with CTRL+SHIFT+ENTER with data in A2:C10 and D1="x":
=SUM(IF(C2:C10=D1,IF(COUNTIFS(A2:A10,A2:A10,B2:B10,">"&B2:B10,C2:C10,D1)=0,B2:B10)))
but note that if there might be more than one max value for a category this sums multiple values. To sum unique max values per category you could try this alternative (also with CSE):
=SUM(IF(C2:C10=D1,(MATCH(A2:A10,IF(COUNTIFS(A2:A10,A2:A10,B2:B10,">"&B2:B10,C2:C10,D1)=0,A2:A10),0)=ROW(A2:A10)-MIN(ROW(A2:A10))+1)*B2:B10))
For example changing the first value from 3 to 1 gives 7 in the first formula and 6 in the second.

Resources