Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have a power query script that imports a csv file (which is tab delimited with "" text qualifiers) from a SharePoint folder - it works fine when I am using the desktop version of Power BI but when I use the same script in Power Query in a Dataverse dataflow it still imports the file but the contents are garbled (all of the header names are in a single column with null entries and there are multiple columns with random characters) - kinda looks like the wrong file encoding is being used but there are no steps in the script that specifiy this? This is the query (with fictitiuos urls and folders):
let
// Gets all files from SharePoint Teams Site
Source = SharePoint.Files(" https://random.sharepoint.com/sites/randomsite/", [ApiVersion = 15]),
// Filter to the folder that should contain the CSV files containing dashboard data.
#"Filter To Appropriate Folder" = Table.SelectRows(Source, each Text.Contains([Folder Path], "/randomfolder” BI")),
// Ensures only CSVs are attempted to be read
#"Filter To Only .CSV" = Table.SelectRows(#"Filter To Appropriate Folder", each [Extension] = ".csv"),
#"Get Latest Data Item" = Table.SelectRows(#"Filter To Only .CSV", let latest = List.Max(#"Filter To Only .CSV"[Date created]) in each [Date created] = latest),
#"Filtered Hidden Files1" = Table.SelectRows(#"Get Latest Data Item", each [Attributes]?[Hidden]? <> true),
#"Filtered Hidden Files2" = Table.SelectRows(#"Filtered Hidden Files1", each [Attributes]?[Hidden]? <> true),
#"Filtered Hidden Files3" = Table.SelectRows(#"Filtered Hidden Files2", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files3", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
#"Filtered Hidden Files4" = Table.SelectRow
s(#"Renamed Columns1", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function2" = Table.AddColumn(#"Filtered Hidden Files4", "Transform File (2)", each #"Transform File (2)"([Content])),
#"Removed Other Columns2" = Table.SelectColumns(#"Invoke Custom Function2", {"Transform File (2)"}),
#"Expanded Table Column2" = Table.ExpandTableColumn(#"Removed Other Columns2", "Transform File (2)", Table.ColumnNames(#"Transform File (2)"(#"Sample File (2)")))
in
#"Expanded Table Column2"
the garbled file contents look like this:
Solved! Go to Solution.
Hello @newby_guy - Please try this sample script below by adding a blank query to your dataflow and using it as the script. This include corrections to the encoding as well as cleaning it up a bit to make it more performant and readable. Also, since you mentioned that you are getting a file (as opposed to compiling data from multiple files, you omit all of the other components such as the function, parameter, sample, transform from sample.
Explanation of the changes to Csv.Document...
Explanation of other optimizations:
Complete script
let
Source = SharePoint.Files("https://random.sharepoint.com/sites/randomsite/", [ApiVersion = 15]),
FilteredRows = Table.SelectRows(Source, each
[Attributes]?[Hidden]? <> true
and Text.Contains ( [Extension], ".csv", Comparer.OrdinalIgnoreCase )
and Text.Contains([Folder Path], "/randomfolder BI", Comparer.OrdinalIgnoreCase )
// and Text.Contains([Name], "sample_tab_delimited", Comparer.OrdinalIgnoreCase ) // file name filter
),
// Get the latest data item
LatestDataItem = Table.SelectRows(FilteredRows, let latest = List.Max(FilteredRows[Date created]) in each [Date created] = latest),
Binary = LatestDataItem{0}[Content],
Content = Csv.Document(Binary,[Delimiter = "#(tab)", Encoding = TextEncoding.Utf8, QuoteStyle = QuoteStyle.Csv]),
PromoteHeaders = Table.PromoteHeaders(Content, [PromoteAllScalars = true])
in
PromoteHeaders
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hi @newby_guy
It might be because of type of your CSV file, Please In the first line, use the following code instead and let me know the change in the result
Csv.Document([Content],
[Delimiter = "#(tab)", Columns = 10, Encoding = TextEncoding.Utf8, QuoteStyle = QuoteStyle.Csv]
)
Omid,
thank you for the suggestion - I added the code to the Transform File(2) script:
Sample File (2):
let
// Gets all files from SharePoint Teams Site
Source = SharePoint.Files"https://random.sharepoint.com/sites/randomsite/", [ApiVersion = 15]),
// Filter to the folder that should contain the CSV files containing dashboard data.
#"Filter To Appropriate Folder" = Table.SelectRows(Source, each Text.Contains([Folder Path], "/randomfolder”)),
// Ensures only CSVs are attempted to be read
#"Filter To Only .CSV" = Table.SelectRows(#"Filter To Appropriate Folder", each [Extension] = ".csv"),
#"Get Latest Data Item" = Table.SelectRows(#"Filter To Only .CSV", let latest = List.Max(#"Filter To Only .CSV"[Date created]) in each [Date created] = latest),
#"Filtered Hidden Files1" = Table.SelectRows(#"Get Latest Data Item", each [Attributes]?[Hidden]? <> true),
#"Filtered Hidden Files2" = Table.SelectRows(#"Filtered Hidden Files1", each [Attributes]?[Hidden]? <> true),
#"Filtered Hidden Files3" = Table.SelectRows(#"Filtered Hidden Files2", each [Attributes]?[Hidden]? <> true),
#"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files3", "Transform File", each #"Transform File"([Content])),
#"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
Navigation1 = #"Renamed Columns1"{0}[Content]
in
Navigation1
Hello @newby_guy - Please try this sample script below by adding a blank query to your dataflow and using it as the script. This include corrections to the encoding as well as cleaning it up a bit to make it more performant and readable. Also, since you mentioned that you are getting a file (as opposed to compiling data from multiple files, you omit all of the other components such as the function, parameter, sample, transform from sample.
Explanation of the changes to Csv.Document...
Explanation of other optimizations:
Complete script
let
Source = SharePoint.Files("https://random.sharepoint.com/sites/randomsite/", [ApiVersion = 15]),
FilteredRows = Table.SelectRows(Source, each
[Attributes]?[Hidden]? <> true
and Text.Contains ( [Extension], ".csv", Comparer.OrdinalIgnoreCase )
and Text.Contains([Folder Path], "/randomfolder BI", Comparer.OrdinalIgnoreCase )
// and Text.Contains([Name], "sample_tab_delimited", Comparer.OrdinalIgnoreCase ) // file name filter
),
// Get the latest data item
LatestDataItem = Table.SelectRows(FilteredRows, let latest = List.Max(FilteredRows[Date created]) in each [Date created] = latest),
Binary = LatestDataItem{0}[Content],
Content = Csv.Document(Binary,[Delimiter = "#(tab)", Encoding = TextEncoding.Utf8, QuoteStyle = QuoteStyle.Csv]),
PromoteHeaders = Table.PromoteHeaders(Content, [PromoteAllScalars = true])
in
PromoteHeaders
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hi,
Thank you @jenratten - for anyone else who stumbles across this issue the csv was a report from some SQL server somwhere and person unknow had altered the type of csv from comma delimited to tab delimited (I did not spot that this detail was described in the other query). In any case you script is much cleaner and easier to follow.
You're very welcome!
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Hello @newby_guy - can you please post the scripts for #"Transform File (2)" and #"Sample File (2)"?
If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.
Proud to be a Microsoft Fabric Super User
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
10 | |
7 | |
7 | |
6 | |
6 |