Power Query M code
(FilePath as text) as table =>
let
Source = Csv.Document(File.Contents(FilePath), [Delimiter = ",", Encoding = 1252]),
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars = true])
in
PromotedHeaders
Defines a query as a function so it can be called with different arguments from other queries.
(FilePath as text) as table =>
let
Source = Csv.Document(File.Contents(FilePath), [Delimiter = ",", Encoding = 1252]),
PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars = true])
in
PromotedHeaders
Paste this as the entire content of a new blank query (name it, for example, fnLoadCsv), then call it elsewhere as fnLoadCsv("C:\data\sales.csv").
Browse all 145 snippets in the Power Query M Code Snippets, or search the library for something similar to Create a Reusable Custom Function.