Forum Discussion

Junaid11's avatar
Junaid11
Helper V
4 years ago
Solved

Unpivot through M or ease

I have below dataset.

StudentCourse1Course2Course3Course1Course2Course1Course2Course3Course1Course2
James01/02/2019 12/08/2000Not CompliantNot CompliantYNY01/02/2021 
Jason28/09/202024/09/201911/09/2015CompliantNot CompliantNYY28/09/202224/09/2021
John17/05/201818/01/2017 Not CompliantNot CompliantNNN17/05/202018/01/2019
Jenny12/01/2021 08/09/2008Not CompliantCompliantYYY12/01/2023 
           
           
           
           
           

This data represents Student and courses they have done. First three course column shows courses and theie completeion date . Next two column shows Compliance of two courses. This goes on. I have done unpivot to see course name and their values in one column but my rows count has increased significantly. My columns have same course name but not all columns/course are repeating. Like course completion date is showing three course while compliance is showing for only two course. I want to see it as below outcome. 

JamesCourse101/02/2019Not CompliantY01/02/2021
JamesCourse2 Not CompliantN 
JamesCourse312/08/2000 Y 
JasonCourse128/09/2020CompliantN28/09/2022
JasonCourse224/09/2019Not CompliantY24/09/2021
JasonCourse311/09/2015 Y 
      

Please help the way it can be done. Either M code or any other solution.

Thanks

2 Replies