Sub topic 2
Promoting Headers and Setting Column Data Types
Assume you know Power BI Desktop, Excel tables, CSV files, and basic table concepts. Power Query is the data-preparation tool inside Power BI. Each action creates an applied step that can be reviewed or changed.
Promote headers and set types
A CSV import often labels columns as Column1, Column2, and so on. Use Home > Use First Row as Headers to promote the first row. Then check each column's data type. A data type tells Power Query how to interpret values, such as dates, whole numbers, decimal numbers, or text.
| Column | Suitable type | Why |
|---|---|---|
| OrderDate | Date | Enables date filtering and time analysis |
| Quantity | Whole number | Supports counting and arithmetic |
| Amount | Decimal number | Preserves monetary values with decimals |
| OrderID | Text or whole number | Depends on whether leading zeros matter |
Set types explicitly instead of relying on automatic detection. Automatic detection can misread dates or identifiers with leading zeros.
let
Source = Csv.Document(
File.Contents("C:\Data\orders.csv"),
[Delimiter = ",", Encoding = 65001, QuoteStyle = QuoteStyle.Csv]
),
Promoted = Table.PromoteHeaders(Source, [PromoteAllScalars = true]),
Typed = Table.TransformColumnTypes(
Promoted,
{{"OrderID", type text}, {"OrderDate", type date}, {"Amount", type number}}
)
in
TypedChoose a SharePoint connection option
Choose the connector based on the object you need:
- SharePoint Folder lists files in a site or document library. Use it for Excel or CSV files and for combining files with the same layout.
- SharePoint Online List connects directly to list items, columns, and metadata.
- SharePoint.Files in Power Query M also lists files and their binary content, which is useful when selecting a specific workbook or CSV.
The SharePoint site URL should identify the site, not a particular file URL.
Read files from SharePoint
For a workbook, filter the file listing by name and folder path, then pass its binary Content to Excel.Workbook. For a CSV, pass Content to Csv.Document. Confirm the encoding and delimiter before promoting headers.
Exercise
Why should you set a column's type after promoting headers?
Show answer
Promoting headers gives the columns their real names, so type transformations can target the intended columns reliably.