March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello everyone,
I build a PowerBI file that targets certain set of CSV files.
I have defined a text parameter called ReportDataFolderPath that defines the folder in which the CSV files exist.
I load the data into Csv.Document data source using File.Contents like that:
let Source = Csv.Document(File.Contents(ReportDataFolderPath & "\subfolder\filewithdata.csv"),[Delimiter=",", Columns=18, Encoding=65001, QuoteStyle=QuoteStyle.Csv]), #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
... the rest is snipped in #"Changed Type3"
This works very well when "filewithdata.csv" exists.
However, sometimes the input set of CSV files does not have "filewithdata.csv". This causes template-to-report loading to fail.
I would like to write some sort of check that validates that "filewithdata.csv" is present in the file system before attempting to load it into Csv.Document function. Can someone suggest a way to do it?
Thank you
Daniel
Solved! Go to Solution.
Hi,
Can you give this code a try!
let Source = Folder.Files("ReportDataFolderPath & "\subfolder\"), #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "filewithdata.csv")), #"Counted Rows" = if Table.RowCount(#"Filtered Rows")= 1 then let SourceFile = Csv.Document(File.Contents("ReportDataFolderPath & "\subfolder\filewithdata.csv"),[Delimiter=",", Columns=18, Encoding=65001, QuoteStyle=QuoteStyle.Csv]), #"Promoted Headers" = Table.PromoteHeaders(SourceFile, [PromoteAllScalars=true]) in #"Promoted Headers" else "File is not found" in #"Counted Rows"
OR check this post it has more sophisticated method: https://community.powerbi.com/t5/Integrations-with-Files-and/How-to-check-if-a-file-exists/m-p/66259...
Hi,
Can you give this code a try!
let Source = Folder.Files("ReportDataFolderPath & "\subfolder\"), #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "filewithdata.csv")), #"Counted Rows" = if Table.RowCount(#"Filtered Rows")= 1 then let SourceFile = Csv.Document(File.Contents("ReportDataFolderPath & "\subfolder\filewithdata.csv"),[Delimiter=",", Columns=18, Encoding=65001, QuoteStyle=QuoteStyle.Csv]), #"Promoted Headers" = Table.PromoteHeaders(SourceFile, [PromoteAllScalars=true]) in #"Promoted Headers" else "File is not found" in #"Counted Rows"
OR check this post it has more sophisticated method: https://community.powerbi.com/t5/Integrations-with-Files-and/How-to-check-if-a-file-exists/m-p/66259...
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
129 | |
90 | |
75 | |
58 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |