Hi Luca Tramontana,
You don’t need Invoke Custom Function for this if the file path is hardcoded in the query. The simplest approach is to store the path in a variable, extract the month/year from the file name, and then add it as a custom column.
let
// Hardcoded path (note the escaped backslashes)
FilePath = "C:\\SERVICE BU\\05 - Tool\\Details_April_2026.xlsx",
// Get file name without extension: Details_April_2026
FileName = Text.BeforeDelimiter(
List.Last(Text.Split(FilePath, "\\")),
"."
),
// Split by "_" and build Month-Year: April-2026
Parts = Text.Split(FileName, "_"),
MonthYear = Parts{1} & "-" & Parts{2},
Source = Excel.Workbook(File.Contents(FilePath), null, true),
#"Export Worksheet_Sheet" = Source{[Item="Export Worksheet", Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Export Worksheet_Sheet", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers", {{"COUNTRY", type text}, {"COUNTRY_ISOCODE", type text}}),
// Add the Month-Year
With this pattern:
-
Details_April_2026.xlsx > April-2026
-
Details_May_2026.xlsx > May-2026
So a custom function isn’t necessary unless you want to reuse the same parsing logic across multiple queries. If you later switch to a Folder source, then parsing from the [Name] (or creating a reusable function) becomes the better scalable approach.
Please let me know if this proves useful to you, or if you would like further assistance.
I'm looking forward to your reply.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment”.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.