Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
tiwari_456
Regular Visitor

Convert from Column to Row.

Hello Mentors,
I am stuck in a data problem, so My scenario is that my source of data is a SharePoint list collection data from any form. Where I have a table named "tblCMP" which consists of 50 + columns for example and replicating the table below in which I have columns like "line1", "line2" and "line3" and dates associated with them like "Date line1", "Date line2" and "Date line3", few other columns as well like "title of change" and  "comments" so it could be a scenario that if a new record gets added it may have detail on "line1" and "Date line1"  but rest of the two columns for line 2 and line 3 could be empty or in other cases and even an empty and all three can be filled so I have to make a Gantt chart over it and combining these columns.

 

tblCMP

IDTitle of ChangeLine1Date Line1Line2Date Line2Line3Date Line3Comments
1TestCase1Complete4/1/2024NANANANATestComment1
2TestCase2Incomplete4/2/2024Discard4/1/2024Complete4/3/2024TestComment2
3TestCase3NANAIncomplete4/3/2024NANATestComment3
4TestCase4Complete4/4/2024NANAIncomplete4/3/2024TestComment2

 

Now I have to make a Gantt Chart out of it, Please assist me with, how I can combine these Lines and their dates to show them all together.

3 REPLIES 3
TheoC
Super User
Super User

Hi @tiwari_456 

 

If I understand correctly, you can achieve this by going into Power Query and unpivoting the Date, Line 1, Line 2, and Line 3.

 

All you need to do in Power Query is select the columns (hold Ctrl button and click on the columns), then right click, and click on Unpivot.  It should work subject to your data structure being appropriate.

 

Let me know how this goes!

 

Theo

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Ashish_Mathur
Super User
Super User

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="tblCMP"]}[Content],
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"ID", "Title of Change", "Comments"}, "Attribute", "Value"),
    #"Split Column by Character Transition" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"Attribute.1", "Attribute.2"}),
    #"Pivoted Column" = Table.Pivot(#"Split Column by Character Transition", List.Distinct(#"Split Column by Character Transition"[Attribute.1]), "Attribute.1", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"}),
    #"Replaced Value" = Table.ReplaceValue(#"Removed Columns","NA","",Replacer.ReplaceValue,{"Line", "Date Line"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Replaced Value",{{"ID", type text}, {"Title of Change", type text}, {"Comments", type text}, {"Line", type text}, {"Date Line", type datetime}})
in
    #"Changed Type"

Hope this helps.

Ashish_Mathur_0-1712275902464.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
TheoC
Super User
Super User

Hi @tiwari_456 

 

If I understand correctly, you can achieve this by going into Power Query and unpivoting the Date, Line 1, Line 2, and Line 3.

 

All you need to do in Power Query is select the columns (hold Ctrl button and click on the columns), then right click, and click on Unpivot.  It should work subject to your data structure being appropriate.

 

Let me know how this goes!

 

Theo

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.