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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Help: Unstructured excel source

Hello everyone,

 

I have an unstructured excel source and I need to transform it. Can anybody help me?

 

Here is the sample data:

 

Company/Feature/ProjectAmount
Company: Company A1600
Feature: Feature 11000
Project AAA200
Project BBB300
Project CCC500
Feature: Feature 2600
Project AAA100
Project BBB200
Project CCC300
  
  
Company: Company B1000
Feature: Feature 11000
Project AAA200
Project BBB300
Project CCC500
Company: Company C1100
Feature: Feature 1500
Project AAA200
Project BBB300
Feature: Feature 2600
Project AAA100
Project BBB200
Project CCC300

 

 

This is the expected output:

 

CompanyFeatureProject Amount
Company AFeature 1Project AAA200
Company AFeature 1Project BBB300
Company AFeature 1Project CCC500
Company AFeature 2Project AAA100
Company AFeature 2Project BBB200
Company AFeature 2Project CCC300
Company BFeature 1Project AAA200
Company BFeature 1Project BBB300
Company BFeature 1Project CCC500
Company CFeature 1Project AAA200
Company CFeature 1Project BBB300
Company CFeature 2Project AAA100
Company CFeature 2Project BBB200
Company CFeature 2Project CCC300

 

Thank you soo much!

1 ACCEPTED SOLUTION
neatdot
Helper I
Helper I

let
    Source = Excel.Workbook(File.Contents("C:\Users\Steve James\Desktop\sample.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Removed Blank Rows" = Table.SelectRows(Sheet1_Sheet, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Removed Top Rows" = Table.Skip(#"Removed Blank Rows",1),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Top Rows",{{"Column1", "Attributes"}, {"Column2", "Amount"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Company", each if Text.Start([Attributes],9)="Company: " then Text.AfterDelimiter([Attributes], ": ") else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Company"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([Attributes], "Company: ")),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows", "Feature", each if Text.Start([Attributes],9) = "Feature: " then Text.AfterDelimiter([Attributes], ": ") else null),
    #"Filled Down1" = Table.FillDown(#"Added Custom1",{"Feature"}),
    #"Added Custom2" = Table.AddColumn(#"Filled Down1", "Project", each if Text.Start([Attributes],8)="Project " then [Attributes] else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each ([Project] <> null)),
    #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows1",{"Attributes", "Company", "Feature", "Project", "Amount"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Attributes"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Company", type text}, {"Feature", type text}, {"Project", type text}, {"Amount", Int64.Type}})
in
    #"Changed Type"

View solution in original post

2 REPLIES 2
neatdot
Helper I
Helper I

let
    Source = Excel.Workbook(File.Contents("C:\Users\Steve James\Desktop\sample.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Removed Blank Rows" = Table.SelectRows(Sheet1_Sheet, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null}))),
    #"Removed Top Rows" = Table.Skip(#"Removed Blank Rows",1),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Top Rows",{{"Column1", "Attributes"}, {"Column2", "Amount"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Company", each if Text.Start([Attributes],9)="Company: " then Text.AfterDelimiter([Attributes], ": ") else null),
    #"Filled Down" = Table.FillDown(#"Added Custom",{"Company"}),
    #"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([Attributes], "Company: ")),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows", "Feature", each if Text.Start([Attributes],9) = "Feature: " then Text.AfterDelimiter([Attributes], ": ") else null),
    #"Filled Down1" = Table.FillDown(#"Added Custom1",{"Feature"}),
    #"Added Custom2" = Table.AddColumn(#"Filled Down1", "Project", each if Text.Start([Attributes],8)="Project " then [Attributes] else null),
    #"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each ([Project] <> null)),
    #"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows1",{"Attributes", "Company", "Feature", "Project", "Amount"}),
    #"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Attributes"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns",{{"Company", type text}, {"Feature", type text}, {"Project", type text}, {"Amount", Int64.Type}})
in
    #"Changed Type"
Anonymous
Not applicable

Thank you soo much! This is what I'm looking for!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.