Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi there,
I want to import multiple csv files in a folder. In the below example, I have 3 csv files in the folder.
How can I import only 2 of the 3 files based on the date in the file name as 2 separate tables ?
Here is what I want:
- table 1: the file with the Max date. So it will the be file, "data_20240619", and rename the table name as "data_current"
- table 2: the date = 1 day prior to the Max date. So it will be the file, "data_20240618", and rename the table name as "data_prior_day"
- reason: my team will continue to save the most recent data file into the same folder, so as new file arrive, I need Power Bi to grab the latest data file and the file -1 day.
Thank you so much for your help!
Thanks, @MaxShema .
Sorry, I am brand new to Power BI, so need a bit hand holding. Appreciate it!
in the step #1 Create a new Query and name it as "data_current"
step #2 Add as a source for this query your folder with the csv files
in step #3 Extract the dates from the names to the separate column
Hi
You can try to do the next way.
Use the next script in M:
= Table.AddColumn(Source, "Date", each
let
// Extract the date part of the string
DatePart = Text.Middle([Name], 5, 8),
YearPart = Text.Start(DatePart, 4),
MonthPart = Text.Middle(DatePart, 4, 2),
DayPart = Text.End(DatePart, 2),
DateText = MonthPart & "/" & DayPart & "/" & YearPart
in
DateText)
4. Change type of column Date to date 🙂
5. Create a list that will contain the maximum value from the Date column.
6. And the last – Filter that row that has value in the Date column equal to MaxDate
Then add separate query “data_prior_day” and do the same but add another one step after calculation a maximum date – calculation the date before maximum.
As result you will get two queries with the one table in each: the table with max date in the name in the query "data_current" and the table with date one day before the max date in “data_prior_day”.
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
65 | |
63 | |
52 | |
37 | |
36 |
User | Count |
---|---|
82 | |
66 | |
61 | |
46 | |
45 |