I have a big dataset which I'm showing here simplified:
I need to check the cells in the columns C to E whether they have an "x" value.
If they do, I need to transfer them in a second table, as well as their corresponding value in the columns A and B.
The outcome should look like this:
I tried If-functions as well as INDEX-functions and VBA coding.
My problem is, that if you got more than one "x" value in a line, I don't know how to return both the first and the second cells as well as for both cells their corresponding values in A and B.
Since OP has tagged Excel
and if one is using MS365
then can use the following formula:
=HSTACK(TOCOL(IFS(C2:E4="x",C1:E1),3),TEXTSPLIT(TEXTAFTER("|"&TOCOL(IFS(C2:E4="x",B2:B4&"|"&A2:A4),3),"|",{1,2}),"|"))
Using LET() to make readability easier,
=LET(
α, TOCOL(IFS(C2:E4="x",C1:E1),3),
φ, TOCOL(IFS(C2:E4="x",B2:B4&"|"&A2:A4),3),
HSTACK(α,TEXTSPLIT(TEXTAFTER("|"&φ,"|",{1,2}),"|")))
Note: Formulas shown above won't work with Structured References
since it will give #SPILL!
error.
This can be accomplished quickly and easily using POWER QUERY. To achieve this using the said procedure, follow this simple steps using POWER QUERY window UI
:
Table1
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Name", "Value"}, "Attribute", "Value.1"),
#"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Other Columns",{"Attribute", "Value", "Name", "Value.1"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Value.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Attribute", "Frame"}})
in
#"Renamed Columns"