Power Query - how to Find columns in a range

sara121

New Member
Joined
Jul 7, 2022
Messages
23
Office Version
  1. 365
Platform
  1. Windows
Hi Everyone,

I'm trying to transform a table converted from PDF file. The columns converted varies in numbers.
I want to keep columns between "Debit" and "Date" only.
What function can I use to select the range?
so I can remove other columns dynamically.
Thanks a lot.
1677635152783.png
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Why not just use the Columns Icon on the Home Tab and remove the unwanted columns. Can also select columns to keep and remove others with the same Icon.
 
Upvote 0
Because in the next file uploaded, the range could be just "DEBIT" and "DATE" only. or the column number between the "DEBIT" and "DATE" may be changed as well, like "DEBIT", "Column 10", "DATE".
 
Upvote 0
I don't see a means to the end. Good Luck and hope someone else can see it clear.
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tcn = Table.ColumnNames(Source),
    p1 = List.PositionOf(tcn, "DEBIT"),
    p2 = List.PositionOf(tcn, "DATE"),
    Result = Table.SelectColumns(Source, List.Range(tcn, p1, p2-p1+1))
in
    Result
 
Upvote 2
Solution
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tcn = Table.ColumnNames(Source),
    p1 = List.PositionOf(tcn, "DEBIT"),
    p2 = List.PositionOf(tcn, "DATE"),
    Result = Table.SelectColumns(Source, List.Range(tcn, p1, p2-p1+1))
in
    Result
Perfect!
 
Upvote 0
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    tcn = Table.ColumnNames(Source),
    p1 = List.PositionOf(tcn, "DEBIT"),
    p2 = List.PositionOf(tcn, "DATE"),
    Result = Table.SelectColumns(Source, List.Range(tcn, p1, p2-p1+1))
in
    Result
wow.. works like a charm!! Thanks so much!!
 
Upvote 0

Forum statistics

Threads
1,215,970
Messages
6,127,991
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top