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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Tranform listed pdf data into an unpivoted table

I am really struggling with a PDF import of invoices

 

Attached shows how it's coming in - there are four attributes: Invoice #, Job Number, P.O number and Client.

'Client' is a separate column, the other three are combined into just two columns showing title and value. 

 

I want four columns; Invoice #, Job Number, P.O Number, Client. With the values as rows. 

I tried transposing but it's creating hundreds of columns e.g. Job Number.1 Job.Number.2 etc

 

PLEASE HELP!!!

 

Sample.png

1 ACCEPTED SOLUTION

@Anonymous 

 

My apologies for late reply.

 

Please see the attached file after transforming your sample data.

Please let me know if it helps

 

Here is the M code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdQ/T8MwEAXwrxKFtWrOZ5//zMAAQ+ledWhRB4Y2CAES3x4PCJHcc5yIblXzZP/ke7rdrn24fPYvz6e7w/upXbW2s6ZjMin/vu3Pr4fLV2Pa/eo319zkL57IeBdU5rE/NpuP8/H0lj+5aCPpc7brp3Wz6fP/91tDnoK40l0/JtdZmmcKYmom5wxXTIE9+YpJgMlBUyKnMiNTjkSVmTY5YDJgdgxNYqLKDE3BWMcqMz07Bibu2I9NFpskqMzIJNbqc6ZNFphQx7HJD+aCTJE4+iuYUMexKQjXTLnjpmIa9wmZUMexKZHUTLnjtXeaY0Idl0LHg8rojluV+WtKISbm0lUTFS+QxNdIYh39n4Qajkle9HW64folF5NQmTApUe2VcpkAezEJdSngwTGpjOqSZ5WZ3gNh5uSwyTudUZNL+r7lJrSbsCnXt2Zyjk3FNN4DyCSz3ylRrJlyneQKJtQnX+iTURm9m0RlhiZmQ1S6a2I5FUxen6WXk3aP+iRxsORyZv8N", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Title = _t, Value = _t, Client = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Title", type text}, {"Value", type text}, {"Client", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index]-Number.Mod([Index],4)),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"all", each _, type table [Title=text, Value=text, Client=text, Index=number, Custom=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each Text.Combine(
[all][Value]&List.Distinct([all][Client]),"|")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom.1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Invoice Date", "Invoice #", "Job Number", "P.O. No", "Client"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Invoice Date", type date}, {"Invoice #", Int64.Type}, {"Job Number", Int64.Type}, {"P.O. No", type text}, {"Client", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Custom", "all"})
in
    #"Removed Columns"

View solution in original post

11 REPLIES 11
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

First Unpivot Title and Client Columns using VALUES as values

 

Then Pivot that single column back

Anonymous
Not applicable

@Zubair_Muhammad , You might need to talk me through this - if I unpivot both Attribute and Value columns, I get the attached. I have a feeling you mean me to do something else. 

 

Sorry! Brain dead now thinking about this!

 

Thanks 

 

Capture.PNG

 

 

@Anonymous 

 

Could you copy paste some sample data with expected results?

@Anonymous 

 

Second time you have to PIVOT (NOT UNpivot)

 

Select the Attribute column and select "pivot column" from the Transform tab.

When the Pop Up window appears...use VALUES in the Values Column

Anonymous
Not applicable

@Zubair_Muhammad 

 

Ok I think I can see where you're going but I'm not getting it right. 

 

Attached are three images - the first one is what I get when I first unpivot Title and Client, and then Pivot Value.

The second is the M query code

 

The third is essentially what I have, and what I want to transform it into.

 

Thanks so much for helping with this 🙂My M QueryMy M QueryWhat I get with unpivot and pivotWhat I get with unpivot and pivotWhat I need to transformWhat I need to transform

@Anonymous 

 

Please could you copy paste the "WhatIhave" Table's data  (Copiable format)

 

 

 

 

 

 

Anonymous
Not applicable

No idea if this will work, else I can email it to you??

 

TitleValueClient
InvoiceDate3/31/2019Company 1
Invoice #6001647Company 1
Job Number483809Company 1
P.O. NoEP1060754Company 1
InvoiceDate4/30/2019Company 1
Invoice #6001751Company 1
Job Number484412Company 1
P.O. NoEP1072606Company 1
InvoiceDate5/30/2019Company 4
Invoice #6001904Company 4
Job Number489048Company 4
P.O. NoEP1072606Company 4
InvoiceDate1/31/2019Company 2
Invoice #6001518Company 2
Job Number471342Company 2
P.O. NoEP1060754Company 2
InvoiceDate2/26/2019Company 3
Invoice #6001557Company 3
Job Number475339Company 3
P.O. NoEP1060754Company 3
InvoiceDate3/31/2019Company 3
Invoice #6001648Company 3
Job Number480286Company 3
P.O. NoEP1060754Company 3
InvoiceDate4/30/2019Company 3
Invoice #6001752Company 3
Job Number484411Company 3
P.O. NoEP1072606Company 3
InvoiceDate5/30/2019Company 3
Invoice #6001905Company 3
Job Number489046Company 3
P.O. NoEP1072606Company 3
InvoiceDate1/31/2019Company 5
Invoice #6001517Company 5
Job Number471343Company 5
P.O. NoEP978922Company 5
InvoiceDate2/26/2019Company 5
Invoice #6001556Company 5
Job Number475340Company 5
P.O. NoEP978922Company 5
InvoiceDate3/31/2019Company 5
Invoice #6001650Company 5
Job Number480287Company 5
P.O. NoEP978922Company 5
InvoiceDate5/30/2019Company 5
Invoice #6001906Company 5
Job Number489050Company 5
P.O. NoEP978922Company 5
InvoiceDate1/31/2019Company 7
Invoice #6001520Company 7
Job Number471362Company 7
P.O. NoEP1060754Company 7
InvoiceDate3/31/2019Company 7
Invoice #6001649Company 7
Job Number480294Company 7
P.O. NoEP1060754Company 7
InvoiceDate4/30/2019Company 7
Invoice #6001753Company 7
Job Number484421Company 7
P.O. NoEP1072606Company 7
InvoiceDate5/31/2019Company 7
Invoice #6001908Company 7
Job Number489055Company 7
P.O. NoEP1072606Company 7
InvoiceDate1/31/2019Company 6
Invoice #6001521Company 6
Job Number471345Company 6
P.O. NoEP1022100Company 6
InvoiceDate2/26/2019Company 6
Invoice #6001560Company 6
Job Number475341Company 6
P.O. NoEP1065856Company 6

Hi,

This M code works

let
    Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Title", type text}, {"Value", type any}, {"Client", type text}}),
    #"Inserted Merged Column" = Table.AddColumn(#"Changed Type", "Merged", each Text.Combine({[Title], [Client]}, ":"), type text),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted Merged Column",{"Title", "Client"}),
    Partition = Table.Group(#"Removed Columns", {"Merged"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
    #"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"Value", "Index"}, {"Value", "Index"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Expanded Partition", "Merged", Splitter.SplitTextByDelimiter(":", QuoteStyle.Csv), {"Merged.1", "Merged.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Merged.1", type text}, {"Merged.2", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type1", List.Distinct(#"Changed Type1"[Merged.1]), "Merged.1", "Value"),
    #"Removed Columns1" = Table.RemoveColumns(#"Pivoted Column",{"Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns1",{"InvoiceDate", "Invoice #", "Job Number", "P.O. No", "Merged.2"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Merged.2", "Client"}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Renamed Columns", {{"InvoiceDate", type date}}, "en-US")
in
    #"Changed Type with Locale"

Hope this helps.

Untitled.png


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

@Anonymous 

 

My apologies for late reply.

 

Please see the attached file after transforming your sample data.

Please let me know if it helps

 

Here is the M code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdQ/T8MwEAXwrxKFtWrOZ5//zMAAQ+ledWhRB4Y2CAES3x4PCJHcc5yIblXzZP/ke7rdrn24fPYvz6e7w/upXbW2s6ZjMin/vu3Pr4fLV2Pa/eo319zkL57IeBdU5rE/NpuP8/H0lj+5aCPpc7brp3Wz6fP/91tDnoK40l0/JtdZmmcKYmom5wxXTIE9+YpJgMlBUyKnMiNTjkSVmTY5YDJgdgxNYqLKDE3BWMcqMz07Bibu2I9NFpskqMzIJNbqc6ZNFphQx7HJD+aCTJE4+iuYUMexKQjXTLnjpmIa9wmZUMexKZHUTLnjtXeaY0Idl0LHg8rojluV+WtKISbm0lUTFS+QxNdIYh39n4Qajkle9HW64folF5NQmTApUe2VcpkAezEJdSngwTGpjOqSZ5WZ3gNh5uSwyTudUZNL+r7lJrSbsCnXt2Zyjk3FNN4DyCSz3ylRrJlyneQKJtQnX+iTURm9m0RlhiZmQ1S6a2I5FUxen6WXk3aP+iRxsORyZv8N", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Title = _t, Value = _t, Client = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Title", type text}, {"Value", type text}, {"Client", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index]-Number.Mod([Index],4)),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"all", each _, type table [Title=text, Value=text, Client=text, Index=number, Custom=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each Text.Combine(
[all][Value]&List.Distinct([all][Client]),"|")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom.1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Invoice Date", "Invoice #", "Job Number", "P.O. No", "Client"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Invoice Date", type date}, {"Invoice #", Int64.Type}, {"Job Number", Int64.Type}, {"P.O. No", type text}, {"Client", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Custom", "all"})
in
    #"Removed Columns"
Anonymous
Not applicable

@Zubair_Muhammad YOU. Are an absolute STAR. 

 

I would never in a million years have been able to figure this out for myself, but it makes perfect sense now I've seen your steps - you are a genius of epic proportions and I will forever be in your debt. 

Utterly fantastic. 

 

Thank you SO much! 

@Anonymous 

 

My apologies for late reply.

 

Please see the attached file after transforming your sample data.

Please let me know if it helps

 

Here is the M code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rdQ/T8MwEAXwrxKFtWrOZ5//zMAAQ+ledWhRB4Y2CAES3x4PCJHcc5yIblXzZP/ke7rdrn24fPYvz6e7w/upXbW2s6ZjMin/vu3Pr4fLV2Pa/eo319zkL57IeBdU5rE/NpuP8/H0lj+5aCPpc7brp3Wz6fP/91tDnoK40l0/JtdZmmcKYmom5wxXTIE9+YpJgMlBUyKnMiNTjkSVmTY5YDJgdgxNYqLKDE3BWMcqMz07Bibu2I9NFpskqMzIJNbqc6ZNFphQx7HJD+aCTJE4+iuYUMexKQjXTLnjpmIa9wmZUMexKZHUTLnjtXeaY0Idl0LHg8rojluV+WtKISbm0lUTFS+QxNdIYh39n4Qajkle9HW64folF5NQmTApUe2VcpkAezEJdSngwTGpjOqSZ5WZ3gNh5uSwyTudUZNL+r7lJrSbsCnXt2Zyjk3FNN4DyCSz3ylRrJlyneQKJtQnX+iTURm9m0RlhiZmQ1S6a2I5FUxen6WXk3aP+iRxsORyZv8N", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Title = _t, Value = _t, Client = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Title", type text}, {"Value", type text}, {"Client", type text}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each [Index]-Number.Mod([Index],4)),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"Custom"}, {{"all", each _, type table [Title=text, Value=text, Client=text, Index=number, Custom=number]}}),
    #"Added Custom1" = Table.AddColumn(#"Grouped Rows", "Custom.1", each Text.Combine(
[all][Value]&List.Distinct([all][Client]),"|")),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Added Custom1", "Custom.1", Splitter.SplitTextByDelimiter("|", QuoteStyle.Csv), {"Invoice Date", "Invoice #", "Job Number", "P.O. No", "Client"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Invoice Date", type date}, {"Invoice #", Int64.Type}, {"Job Number", Int64.Type}, {"P.O. No", type text}, {"Client", type text}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type1",{"Custom", "all"})
in
    #"Removed Columns"

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.