Forum Discussion
Jacb
1 year agoFrequent Visitor
How to deal with multiple headers in data in Power BI
Hi, I am trying to read in the data from PDF document that contains operational stats. The data from the PDF file looks like this. When the PDF file is read into Power BI - Power BI iden...
- 1 year ago
Use this
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]), #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each [Log In] <> null), #"Added Agent Id" = Table.AddColumn(#"Filtered Rows", "Agent Id", each if Text.StartsWith(Text.From([Log In]),"Agent Id",Comparer.OrdinalIgnoreCase) then [Log Out] else null), #"Added Agent Name" = Table.AddColumn(#"Added Agent Id", "Agent Name", each if Text.StartsWith(Text.From([Log In]),"Agent Name",Comparer.OrdinalIgnoreCase) then [Log Out] else null), #"Added Date" = Table.AddColumn(#"Added Agent Name", "Date", each if [Log Out] = null then [Log In] else null), #"Filled Down" = Table.FillDown(#"Added Date",{"Agent Id", "Agent Name", "Date"}), #"Filtered Data Rows Only" = Table.SelectRows(#"Filled Down", each [Log In] <> "Agent Id:"and [Log In] <> "Agent Name:"and [Log Out] <> null), #"Reordered Columns" = Table.ReorderColumns(#"Filtered Data Rows Only",{"Agent Id", "Agent Name", "Date", "Log In", "Log Out", "Login", "Available T", "Released T", "Available", "Released", "In Call T", "Media Type", "Calls", "Avg T To", "Max T To"}) in #"Reordered Columns"to produce this:
from this Excel Data:
PwerQueryKees
1 year agoSuper User
Use this
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each [Log In] <> null),
#"Added Agent Id" = Table.AddColumn(#"Filtered Rows", "Agent Id", each if Text.StartsWith(Text.From([Log In]),"Agent Id",Comparer.OrdinalIgnoreCase) then [Log Out] else null),
#"Added Agent Name" = Table.AddColumn(#"Added Agent Id", "Agent Name", each if Text.StartsWith(Text.From([Log In]),"Agent Name",Comparer.OrdinalIgnoreCase) then [Log Out] else null),
#"Added Date" = Table.AddColumn(#"Added Agent Name", "Date", each if [Log Out] = null then [Log In] else null),
#"Filled Down" = Table.FillDown(#"Added Date",{"Agent Id", "Agent Name", "Date"}),
#"Filtered Data Rows Only" = Table.SelectRows(#"Filled Down", each [Log In] <> "Agent Id:"and [Log In] <> "Agent Name:"and [Log Out] <> null),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Data Rows Only",{"Agent Id", "Agent Name", "Date", "Log In", "Log Out", "Login", "Available T", "Released T", "Available", "Released", "In Call T", "Media Type", "Calls", "Avg T To", "Max T To"})
in
#"Reordered Columns"
to produce this:
from this Excel Data:
- Jacb1 year agoFrequent Visitor
Thank you - this worked!
I just had to follow your steps as my source was a PDF document but I was still able to use the other steps and it worked.
Thanks again
JB