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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
rkords
Regular Visitor

Only import Files in a Timerange from Folder

Hello,

 

i have a huge amount of logfiles in a folder. I only want to import files in a certain timerange, which I can define in a worksheet(TR_Begin and TR_End variables). I managed to filter the files in the sample file query, but in in the transform sample file query I see data from all my logfiles again.

Here is the code of my sample file query:

 

let
    EMS_Name = Excel.CurrentWorkbook(){[Name="EMS_Name"]}[Content]{0}[Column1],
    TR_Begin_Y = Excel.CurrentWorkbook(){[Name="TR_Begin_Y"]}[Content]{0}[Column1],
    TR_Begin_M = Excel.CurrentWorkbook(){[Name="TR_Begin_M"]}[Content]{0}[Column1],
    TR_Begin_D = Excel.CurrentWorkbook(){[Name="TR_Begin_D"]}[Content]{0}[Column1],
    TR_End_Y = Excel.CurrentWorkbook(){[Name="TR_End_Y"]}[Content]{0}[Column1],
    TR_End_M = Excel.CurrentWorkbook(){[Name="TR_End_M"]}[Content]{0}[Column1],
    TR_End_D = Excel.CurrentWorkbook(){[Name="TR_End_D"]}[Content]{0}[Column1],
    Source = Folder.Files("C:\Users\user\work\project\EMS-V4-" & EMS_Name),
    #"Filtered Rows" = Table.SelectRows(Source, each [Date modified] >= #datetime(TR_Begin_Y, TR_Begin_M, TR_Begin_D, 0, 0, 0) and [Date created] <= #datetime(TR_End_Y, TR_End_M, TR_End_D, 0, 0, 0)),
    #"C:\Users\user\work\project\EMS-V4-000A\_log_20220127145524" = #"Filtered Rows"{0}[Content]
in
    #"C:\Users\user\work\project\EMS-V4-000A\_log_20220127145524"

 

 Thanks for your support.

3 REPLIES 3
KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @rkords,

 

KT_Bsmart2gethe_0-1651752265980.png

Filter for the start date and end date should be applied before the invoked step:

KT_Bsmart2gethe_1-1651752410364.png

 

Please see below code (see above pic indicate where the code should go):

let
EMS_Name = Excel.CurrentWorkbook(){[Name="EMS_Name"]}[Content]{0}[Column1],
TR_Begin_Y = Excel.CurrentWorkbook(){[Name="TR_Begin_Y"]}[Content]{0}[Column1],
TR_Begin_M = Excel.CurrentWorkbook(){[Name="TR_Begin_M"]}[Content]{0}[Column1],
TR_Begin_D = Excel.CurrentWorkbook(){[Name="TR_Begin_D"]}[Content]{0}[Column1],
TR_End_Y = Excel.CurrentWorkbook(){[Name="TR_End_Y"]}[Content]{0}[Column1],
TR_End_M = Excel.CurrentWorkbook(){[Name="TR_End_M"]}[Content]{0}[Column1],
TR_End_D = Excel.CurrentWorkbook(){[Name="TR_End_D"]}[Content]{0}[Column1],

StartDate = #datetime(TR_Begin_Y, TR_Begin_M, TR_Begin_D, 0, 0, 0)
EndDate = #datetime(TR_End_Y, TR_End_M, TR_End_D, 0, 0, 0)

 

Source = Folder.Files("C:\Users\user\work\project\EMS-V4-" & EMS_Name),
#"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
#"Filtered Rows" = Table.SelectRows(#"Filtered Hidden Files1", each [Date created] >= StartDate and [Date created] <= EndDate,
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Rows", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
#"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File")))
in
#"Expanded Table Column1"

 

Regards

KT

 

 

 

Anonymous
Not applicable

Hi @rkords ,

 

Have you tried Date/Time Filters after importing the data?

vstephenmsft_0-1651733633690.png

 

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

jennratten
Super User
Super User

The source for the Transform Sample File query should one file only (usually determined by a parameter) and should return an error if more than one or none are being returned.   Your script for Transform Sample File should look someting like this:

jennratten_0-1650904478522.png

 

In the query that invokes the function you will need to apply the folder filters again - those applied in the sample file query are not applied when the function is invoked.   

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.

Top Kudoed Authors