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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
conniedevina
Helper I
Helper I

To pick latest file excel in a folder but it can be multiple file

Hi All,

 

I have an issue that I have these year folder

2021, and 2022 folder.. I want to pick up the latest file from each folder. but the file format might be like this

1a. - for January

2a. - for February and so on..

let's say this the structure of the folder and files

2021

1a. ABC

2a. ABC

 

2022

1a. ABC

2a. ABC

2a. BCD

 

I would like my power bi pickup data 

2021 -> 2a. ABC

2022 -> 2a. ABC and 2a. BCD

 

this number will be added based on the month, is this possible to be done? as I check the forum they mostly the answer about latest 1 file.

Would appreciate any help!

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @conniedevina ,

 

For this try the following:

 

  • Add custom column with the beginning of the file name (text before delimiter):

MFelix_0-1702892249044.pngMFelix_1-1702892266297.png

 

  • Add another one with text After Delimiter

 

MFelix_2-1702892290453.png

MFelix_3-1702892310761.png

 

  • In both cases delimiter mus be the space
  • Do a group by folder and Text After Delimiter column using the MAX of the Text before delimiter, and all the rows:

MFelix_4-1702892395284.png

 

  • Expand all the columns on the Value column except for the folder path and text after delimiter
  • MFelix_5-1702892443644.png

     

  • Add the following colum to you table:
[Name] = [FileStart] & " " &[Text After Delimiter]

MFelix_6-1702892566158.png

 

  • Filter out all the false values

MFelix_7-1702892594666.png

 

Complete code below:

let
    Source = Folder.Files("C:\Test"),
    #"Inserted Text Before Delimiter" = Table.AddColumn(Source, "Text Before Delimiter", each Text.BeforeDelimiter([Name], " "), type text),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([Name], " "), type text),
    #"Grouped Rows" = Table.Group(#"Inserted Text After Delimiter", {"Folder Path", "Text After Delimiter"}, {{"FileStart", each List.Max([Text Before Delimiter]), type text}, {"Value", each _, type table [Content=binary, Name=text, Extension=text, Date accessed=nullable datetime, Date modified=nullable datetime, Date created=nullable datetime, Attributes=nullable record, Folder Path=text, Text Before Delimiter=text, Text After Delimiter=text]}}),
    #"Expanded Value" = Table.ExpandTableColumn(#"Grouped Rows", "Value", {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Text Before Delimiter"}, {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Text Before Delimiter"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Value", "Custom", each [Name] = [FileStart] & " " &[Text After Delimiter]),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true))
in
    #"Filtered Rows"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @conniedevina ,

 

For this try the following:

 

  • Add custom column with the beginning of the file name (text before delimiter):

MFelix_0-1702892249044.pngMFelix_1-1702892266297.png

 

  • Add another one with text After Delimiter

 

MFelix_2-1702892290453.png

MFelix_3-1702892310761.png

 

  • In both cases delimiter mus be the space
  • Do a group by folder and Text After Delimiter column using the MAX of the Text before delimiter, and all the rows:

MFelix_4-1702892395284.png

 

  • Expand all the columns on the Value column except for the folder path and text after delimiter
  • MFelix_5-1702892443644.png

     

  • Add the following colum to you table:
[Name] = [FileStart] & " " &[Text After Delimiter]

MFelix_6-1702892566158.png

 

  • Filter out all the false values

MFelix_7-1702892594666.png

 

Complete code below:

let
    Source = Folder.Files("C:\Test"),
    #"Inserted Text Before Delimiter" = Table.AddColumn(Source, "Text Before Delimiter", each Text.BeforeDelimiter([Name], " "), type text),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Inserted Text Before Delimiter", "Text After Delimiter", each Text.AfterDelimiter([Name], " "), type text),
    #"Grouped Rows" = Table.Group(#"Inserted Text After Delimiter", {"Folder Path", "Text After Delimiter"}, {{"FileStart", each List.Max([Text Before Delimiter]), type text}, {"Value", each _, type table [Content=binary, Name=text, Extension=text, Date accessed=nullable datetime, Date modified=nullable datetime, Date created=nullable datetime, Attributes=nullable record, Folder Path=text, Text Before Delimiter=text, Text After Delimiter=text]}}),
    #"Expanded Value" = Table.ExpandTableColumn(#"Grouped Rows", "Value", {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Text Before Delimiter"}, {"Content", "Name", "Extension", "Date accessed", "Date modified", "Date created", "Attributes", "Text Before Delimiter"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Value", "Custom", each [Name] = [FileStart] & " " &[Text After Delimiter]),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true))
in
    #"Filtered Rows"

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.