how to extract numbers from file names in an excel query?

yabi100

Board Regular
Joined
Aug 10, 2013
Messages
89
Office Version
  1. 2016
Platform
  1. Windows
I have four files in a folder. Names contain text and numbers. I want to extract numbers in a query and assign them into a column. These numbers are years and I want to build a year column in the query. I don't know how to extract numbers from file names in a query?
 
Last edited:

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Which version of Office do you have? (please update your profile as it will influence the possible solutions that can be offered) Also, is there any pattern to where the numbers might appear?
 
Upvote 0
Which version of Office do you have? (please update your profile as it will influence the possible solutions that can be offered) Also, is there any pattern to where the numbers might appear?
I am using excel 2016. Yes there is a pattern. Filename format is as follows: year ** of sales. ** are numbers. Two digits for years are the 5th and 6th character.
 
Upvote 0
You can use a custom column with a formula like:

Power Query:
=Text.Range([Filename],4,2)

Note that the start position goes from 0 so 4 is the 5th character.
 
Upvote 0
[Filename]
Are the brackets [] also part of the formula?
Does it matter, which filename should be put in the formula?
I did it withou brackets and put the first file name with 08 as numbers. It returned 08 for all 4 rows. they should be 08, 09, 10,11
 
Upvote 0
FileName is the name of the column that has the filenames in it.
 
Upvote 0
Solution
A
Are the brackets [] also part of the formula?
Does it matter, which filename should be put in the formula?
I did it withou brackets and put the first file name with 08 as numbers. It returned 08 for all 4 rows. they should be 08, 09, 10,11
As they are numbers, I used "Add Index Column" and put the formula as follows: starting index: 11, increment -1. It solved my problem but I don't like it. Will be happy to hear comment on format for filename.
Which website, can I find more on formula formats for Power Query?
 
Upvote 0

Forum statistics

Threads
1,225,375
Messages
6,184,611
Members
453,247
Latest member
scouterjames

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