Transpose Data and Expand Names Based on Courses Pending

Sufiyan97

Well-known Member
Joined
Apr 12, 2019
Messages
1,615
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
I have below row data shown as below in sample and I want a formula to populate expected results shown


Book5
ABCDEFGHIJK
1Row DataExpected Result
2NameCourse Name 1Course Name 2Course Name 3Course Name 4Course Name 5NameCourses
3Name 1Course1Course2Name 1Course1
4Name 2Course1Name 1Course2
5Name 3Course1Course2Course3Name 2Course1
6Name 4Course1Course2Course3Course4Course5Name 3Course1
7Name 5Course1Course2Name 3Course2
8Name 3Course3
9Name 4Course1
10Name 4Course2
11Name 4Course3
12Name 4Course4
13Name 4Course5
14Name 5Course1
15Name 5Course2
16
Sheet1
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
I have below row data shown as below in sample and I want a formula to populate expected results shown


Book5
ABCDEFGHIJK
1Row DataExpected Result
2NameCourse Name 1Course Name 2Course Name 3Course Name 4Course Name 5NameCourses
3Name 1Course1Course2Name 1Course1
4Name 2Course1Name 1Course2
5Name 3Course1Course2Course3Name 2Course1
6Name 4Course1Course2Course3Course4Course5Name 3Course1
7Name 5Course1Course2Name 3Course2
8Name 3Course3
9Name 4Course1
10Name 4Course2
11Name 4Course3
12Name 4Course4
13Name 4Course5
14Name 5Course1
15Name 5Course2
16
Sheet1
There is probably a more concise way though.

Book1
ABCDEFGHIJ
1Row DataExpected Result
2NameCourse Name 1Course Name 2Course Name 3Course Name 4Course Name 5NameCourses
3Name 1Course1Course2Name 1Course1
4Name 2Course1Name 1Course2
5Name 3Course1Course2Course3Name 2Course1
6Name 4Course1Course2Course3Course4Course5Name 3Course1
7Name 5Course1Course2Name 3Course2
8Name 3Course3
9Name 4Course1
10Name 4Course2
11Name 4Course3
12Name 4Course4
13Name 4Course5
14Name 5Course1
15Name 5Course2
Sheet1
Cell Formulas
RangeFormula
I3:J15I3=HSTACK(WRAPROWS(TEXTSPLIT(TEXTJOIN(",",TRUE,REPT($A$3:$A$7 & ",",BYROW($B$3:$F$7,COUNTA))),",",,TRUE),1),TRANSPOSE(TEXTSPLIT(TEXTJOIN(",",TRUE,$B$3:$F$7),",",,TRUE)))
Dynamic array formulas.
 
Upvote 0
An alternative is to use Power Query and Unpivot your data

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Name"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Other Columns",{"Attribute"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Value", "Cources"}})
in
    #"Renamed Columns"
 
Upvote 0
Another possibility for Office 365:

Excel Formula:
=LET(
    data, A3:F7,
    labels, TAKE(data,,1),
    values, DROP(data,,1),
    unpvtλ, LAMBDA(area,TOCOL(IFS(values<>"",area),2)),
    HSTACK(unpvtλ(labels),unpvtλ(values))
)

Adjust the data range reference as needed.
 
Upvote 0
Another option
Excel Formula:
=HSTACK(TOCOL(IF(B3:F10<>"",A3:A10,1/0),2),TOCOL(B3:F10,1))
 
Upvote 0
Solution
You're welcome. Just a friendly word of caution for the chosen solution...

Excel Formula:
=HSTACK(TOCOL(IF(B3:F10<>"",A3:A10,1/0),2),TOCOL(B3:F10,1))

...could potentially return incorrect results if range B3:F10 includes cells with empty strings. Array1 will exclude blank cells and cells containing empty strings, whereas array2 will exclude blank cells only. To play it safe, the logical_test argument should be NOT(ISBLANK(B3:F10)), or just ISBLANK(B3:F10) with the value_if_true and value_if_false arguments reversed:

Excel Formula:
=HSTACK(TOCOL(IF(ISBLANK(B3:F10),1/0,A3:A10),2),TOCOL(B3:F10,1))

However, this method still won't remove cells with empty strings, if present.
 
Upvote 0
If you are unsure on how to implement the PQ solution, here are some videos to help you understand that approach.

Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 1
Thanks Alan, thanks for PQ resources, I will definitely look and learn.

I’m already familiar with how to use Power Query codes, but I’m excited to dive deeper and explore more advanced techniques using the resources you've provided.

here is result with code you have provided

Excel Practice 12.17.24.xlsx
ABCD
1NameCources
2Name 1Course1
3Name 1Course2
4Name 2Course1
5Name 3Course1
6Name 3Course2
7Name 3Course3
8Name 4Course1
9Name 4Course2
10Name 4Course3
11Name 4Course4
12Name 4Course5
13Name 5Course1
14Name 5Course2
15
Table3
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,225,726
Messages
6,186,669
Members
453,368
Latest member
xxtanka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top