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
Super User
1 year agoIt is always a bit of trial and error.
Here Iwould probaly
- start by removing empty lines.
- Then Transpose
- Creeate 3 new columns for AgentId, Agent Name and the data
Using an if expression to do that only for the lines where they actually occur - Then do a fill down on these columns
- Then remove the AgentId, name and Date rows
This would be a good start I think...
Did I answer your question? Then please mark my post as the solution and make it easier to find for others having a similar problem.
If I helped you, please click on the Thumbs Up to give Kudos.
Kees Stolker
A big fan of Power Query and Excel