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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Anonymous
Not applicable

How to delete all rows except the first one?

Hi,

 

The source is a folder which contains many pdf files. All of them have only one table with at least one row of headers and some rows of data. A few files just show the table with the headers but no further content.

I only need the first row with content of each file. If there are more rows then they must be ignored.

The problem comes up at the files which have no content but only the headers as the counter of single lines goes negative.

I suppose there are far better ways to achieve my goal but yet I don't know them. Any advice would be appreciated, here's my approach:

 

 

let
    Quelle = Pdf.Tables(Parameter1, [Implementation="1.3"]),
    Table001 = Quelle{[Id="Table001"]}[Data],
    #"headers" = Table.PromoteHeaders(Table001, [PromoteAllScalars=true]),
    #"number of rows" = Table.RowCount(#"headers"),
    #"single line" = (#"number of rows")-1,
    #"result" = Table.RemoveRows(#"headers", 1, (#"single line"))
in
    #"result"

 

 

1 ACCEPTED SOLUTION
edhans
Community Champion
Community Champion

You can count the rows with Table.RowCount, so your formula would be something like

 

ValidationStep = if Table.RowCount(PreviousStep) > 1 then {your filter here} else PreviousStep

 

 

So this maybe:

let
    Quelle = Pdf.Tables(Parameter1, [Implementation="1.3"]),
    Table001 = Quelle{[Id="Table001"]}[Data],
    #"headers" = Table.PromoteHeaders(Table001, [PromoteAllScalars=true]),
    #"number of rows" = Table.RowCount(#"headers"),
    #"single line" = (#"number of rows")-1,
    #"result" = if #"number of rows" > 1 then Table.RemoveRows(#"headers", 1, (#"single line")) else #"single line"
in
    #"result"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

You could do your row count before promoting the headers, so your empty tables will instead have one row. Then delete the tables that have only one row, so your -1 becomes 0, and only then promote the headers. 

--Nate 

edhans
Community Champion
Community Champion

You can count the rows with Table.RowCount, so your formula would be something like

 

ValidationStep = if Table.RowCount(PreviousStep) > 1 then {your filter here} else PreviousStep

 

 

So this maybe:

let
    Quelle = Pdf.Tables(Parameter1, [Implementation="1.3"]),
    Table001 = Quelle{[Id="Table001"]}[Data],
    #"headers" = Table.PromoteHeaders(Table001, [PromoteAllScalars=true]),
    #"number of rows" = Table.RowCount(#"headers"),
    #"single line" = (#"number of rows")-1,
    #"result" = if #"number of rows" > 1 then Table.RemoveRows(#"headers", 1, (#"single line")) else #"single line"
in
    #"result"


Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors