filmov
tv
Power Query: Avoiding naming column headers to avoid breaks
Показать описание
Queries in Power BI and Excel often break because of a small change to a column header. Many actions refer to these column headers. I go through how to do many common actions without referencing the column headers, including trim, replace values, toGGLe cASe, rename, reorder and even assigning data types. If you subscribe to my channel and request I can transfer over the workbook I used.
There are two options:
No code solution using transpose which does many of the options well but not perfectly
Low code solutions which is more robust and does more. Here are the custom M functions I use:
Create a list of column names: Table.ColumnNames(Source)
Convert values into their type (e.g. date, number etc.): Table.AddColumn(Previous step", "Type", each Value.Type([Column which you want to convert]))
Convert one column to a list: OriginalCol = Previous step [Name of col]
Zipped list with 2 lists: The column name & its type: List.Zip({Col name,Column with data type})
The next 3 I did all in one step at the end:
Transform data types for column headers: Table.TransformColumnTypes()
Apply renamed column headers: Table.RenameColumns()
Which columns to keep: Table.SelectColumns()
00:00 - Introduction
01:03 - Power Query settings
02:27 - No code (transpose) method
02:55 - Trim, cASe & rename
03:39 - Choose columns
04:30 - Reorder
07:13 - Trim, cASe, Filter
08:03 - Data types
09:40 - Bring it together
14:21 - Fix data types
There are two options:
No code solution using transpose which does many of the options well but not perfectly
Low code solutions which is more robust and does more. Here are the custom M functions I use:
Create a list of column names: Table.ColumnNames(Source)
Convert values into their type (e.g. date, number etc.): Table.AddColumn(Previous step", "Type", each Value.Type([Column which you want to convert]))
Convert one column to a list: OriginalCol = Previous step [Name of col]
Zipped list with 2 lists: The column name & its type: List.Zip({Col name,Column with data type})
The next 3 I did all in one step at the end:
Transform data types for column headers: Table.TransformColumnTypes()
Apply renamed column headers: Table.RenameColumns()
Which columns to keep: Table.SelectColumns()
00:00 - Introduction
01:03 - Power Query settings
02:27 - No code (transpose) method
02:55 - Trim, cASe & rename
03:39 - Choose columns
04:30 - Reorder
07:13 - Trim, cASe, Filter
08:03 - Data types
09:40 - Bring it together
14:21 - Fix data types
Комментарии