How to merge rows based on value in one column in Excel? - excel

I want to merge/concatenate rows if those rows have a duplicate values in one column. The merge step applies to more than one columns. In de table below I show an example of the problem:
+-----+--------+--------+--------+--------+--------+----------+
| | A | B | C | D | E | F |
+-----+--------+--------+--------+--------+--------+----------+
| Dog | | | param1 | | | |
+-----+--------+--------+--------+--------+--------+----------+
| Dog | param2 | | | | | |
+-----+--------+--------+--------+--------+--------+----------+
| Dog | | | | | | |
+-----+--------+--------+--------+--------+--------+----------+
| Dog | | | | | | param3 |
+-----+--------+--------+--------+--------+--------+----------+
| Cat | | param5 | | | | |
+-----+--------+--------+--------+--------+--------+----------+
| Cat | | | | param6 | | |
+-----+--------+--------+--------+--------+--------+----------+
I have about 4000 unique row values and about 30 columns. The duplicate row values are ranging from n=1 to n=10.
My preferred table:
+-----+--------+--------+--------+--------+--------+----------+
| | A | B | C | D | E | F |
+-----+--------+--------+--------+--------+--------+----------+
| Dog | param2 | | param1 | | | param3 |
+-----+--------+--------+--------+--------+--------+----------+
| Cat | | param5 | | param6 | | |
+-----+--------+--------+--------+--------+--------+----------+
Can this be done in Excel with some magic or do I need advanced stuff like python for this?
I have tried multiple formula's with CONCATINATE but to no success.
Thank you in advance

This can also be accomplished using Power Query, available in Windows Excel 2010+ and Excel 365 (Windows or Mac)
To use Power Query
Select some cell in your Data Table
Data => Get&Transform => from Table/Range
When the PQ Editor opens: Home => Advanced Editor
Make note of the Table Name in Line 2
Paste the M Code below in place of what you see
Change the Table name in line 2 back to what was generated originally.
Read the comments and explore the Applied Steps to understand the algorithm
M Code
let
//change next line to reflect actual data source
Source = Excel.CurrentWorkbook(){[Name="Table10"]}[Content],
//set all columns to data type text
#"Changed Type" = Table.TransformColumnTypes(Source,
List.Transform(Table.ColumnNames(Source), each {_, type text})),
//Group by Animal
//Then "Fill Up" each column and return only the first row
#"Group Animal" = Table.Group(#"Changed Type","Animal",
{"Consolidate", each Table.FillUp(_,Table.ColumnNames(_)){0}}),
//Expand the grouped table and re-set the data types to text
#"Expanded Consolidate" = Table.ExpandRecordColumn(#"Group Animal", "Consolidate",
List.RemoveFirstN(Table.ColumnNames(#"Changed Type"))),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded Consolidate", List.Transform(Table.ColumnNames(#"Expanded Consolidate"), each {_, type text}))
in
#"Expanded Consolidate"

Tricky. One way is to nest REDUCE() in another:
Formula in A8:
=DROP(REDUCE(0,UNIQUE(A1:A6),LAMBDA(a,b,VSTACK(a,REDUCE(b,SEQUENCE(6),LAMBDA(x,y,HSTACK(x,#SORT(INDEX(FILTER(B1:G6&"",A1:A6=b),,y),,-1))))))),1)
Or, a bit more dynamic:
=LET(r,A1:G6,s,TAKE(r,,1),t,DROP(r,,1)&"",DROP(REDUCE(0,UNIQUE(s),LAMBDA(a,b,VSTACK(a,REDUCE(b,SEQUENCE(COLUMNS(t)),LAMBDA(x,y,HSTACK(x,#SORT(INDEX(FILTER(t,s=b),,y),,-1))))))),1))

Highlight the values you need to be grouped together then go to data, click on groe tab

Related

Count matches of entire record in two separate tables - excel

Ive been trying to find a formula which would count me the match between two tables (like inner join) in excel.
I have a table1 with columns(ID,UserName,Function) and table2 (UserName,Function, etc...) need to count an explicit matches of table1(UserName&Function) and table2(UserName&Function)
tried sumproduct(--(table1[UserName:Function]=table2[UserName:Function]) but it seems like it compares it column by column and returns incorrect value, i tried to concatenate those columns within sumproduct, but still doesnt work.
Is it possible to make it in one formula or shall i build udf with sql query?
Would it be possible to return the records and list it as an array by using FILTERXML formula?
sample data:
table1:
| ID | UserName | Function |
| -- | -------- | ----------|
| 1 | oopz | FCA4001 |
| 2 | oopz | FCA4002 |
| 3 | arronT | FCA4001 |
table2:
| UserName | Function |
| -------- | ----------|
| randalO | FCA4001 |
| oopz | FCA4001 |
| arronT | FCA4005 |
Thanks in advance!:)

Insert column in another table for two already imported table in Spotfire

My question is, I’m sure, quite easy.
I have two table, including for each a column named ID.
The fist one is having all ID.
The second one is having only few.
I want to work on the missing ID.
Thus, I want to add a flag in my first table if this ID is present in the second table, or not.
I’m using Spotfire 11.4. In a previous version, it was easy to « add column » using a table from the analysis. Now I can’t find it, I have to import again the same table to make the merge.
Do you have any tips ?
Table I
| ID | Country |
| -- | ------- |
| A1 | France |
| A2 | Germany |
| A3 | U.K. |
| A7 | U.S.A. |
Table II
| ID |
| -- |
| A2 |
| A7 |
Expected Table
| ID | Country | flag |
| -- | ------- | ---- |
| A1 | France | 0 |
| A2 | Germany | 1 |
| A3 | U.K. | 0 |
| A7 | U.S.A. | 1 |
Ok, the option is hidden in the "Other" option, when inserting column (or rows) in the data canva.

Conditional column in Power Query

I have a table with 3 columns: Name, Property and Value
All names are unique. But there are cases where, for instance, for different Names , both their properties and values are equal at the same time.
I want to add conditional column that would add all Names with line feed delimiter for which properties and values are equal. So for example, for 1st Name I would go to conditional column and would see list of 5 other names that have the same property and value
So far I have tried adding conditional column:
If Property equals Property Then
Else if Value equals Value Then Name
but it just returns values from name column and I dont know to add up these names together
Thanks!
You could group your rows by Property and Value, then combine the Name of for each row.
= Table.Group(Source, {"Property", "Value"}, {{"Names", each Text.Combine(_[Name], ", "), type text}})
Table.Group - like SQL's GROUP BY
Text.Combine - like array joining in other languages, you provide a list and a separator and receive a string
Original table:
| Name | Property | Value |
| ---- | -------- | ----- |
| A | a | 1 |
| B | b | 2 |
| C | a | 2 |
| D | a | 1 |
| E | b | 2 |
Full query:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Grouped = Table.Group(Source, {"Property", "Value"}, {{"Names", each Text.Combine(_[Name], ", "), type text}})
in
Grouped
Result:
| Property | Value | Names |
| -------- | ----- | ----- |
| a | 1 | A, D |
| b | 2 | B, E |
| a | 2 | C |

Excel how to filter based on ( select columnA = ValueA) OR (select columnB = ValueB)

For example, I have a very simple excel sheet which has the layout and info as following:
| Name | English | French | Chinese | Korean |
|-------------|---------|--------|---------|--------|
| Eddie | Y | | | |
| Raymond | Y | | Y | |
| Celine Dion | Y | Y | | |
| Marion | | Y | | |
I want to filter the rows such that all filtered persons can either speak Chinese OR English
The result will be Eddie, Raymond, Celine.
Assuming that your data is in a table or that you've engaged the autofilter, I would create an extra column called ChineaseOrEnglish in which i'd create an if() statement that uses OR() to place a 'Y' in the column where either English or Chinese is flagged.
You would then be able to filter on the ChineaseOrEnglish column.

Microsoft Excel - Use a drop down list to extract data from another workbook

If i select an option from a drop down list, how do i then display data extracted from another workbook. So far, i have seen examples of showing single row data from another worksheet. But i have yet to see a method of extracting multiple rows and columns of data from a different workbook.
Week 1.xls:
A B C
-------------------------------------------------
| SKU | Description | Vendor Style |
-------------------------------------------------
| | | |
| 000001 | Description 1 | CA0080-03E |
| 000002 | Description 2 | EX1134-59D |
| 000003 | Description 3 | EM0132-59A |
| 000004 | Description 4 | EW8694-52D |
| 000005 | Description 5 | FC0003-18D |
| 000006 | Description 6 | EK2273-59E |
Master.xls:
A B C
------------------------------------------------- ________ _
| SKU | Description | Vendor Style | |________|>| <---Drop Down List
-------------------------------------------------
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
If i choose, e.g. Week 1 in the drop down list. I want the data from Week 1.xls to fill in the table in Master.xls.
If i choose, e.g. Week 2 in the drop down list. I want the data from Week 2.xls to fill in the table in Master.xls.
Is this possible? I'm thinking vlookups may be involved here in order to point to each workbook.
Thank you.

Resources