Most of the time data will need to be imported into the data model from a source so that the connection is 'live' and can be updated by refreshing the source data. It is also possible to enter data straight into the data model through the 'Enter Data' function. This function allows data to be typed or cut & pasted into a table.
This way of entering data can be used to hard code any lookup tables that might currently be Excel files. If the data is hard coded in the model using the process below then the risk of links to files and filenames is mitigated.
Here are the steps required to enter data directly into PowerQuery
- In the ribbon under 'Home' click the 'Enter Data' button to display the 'Create Table' window
- Enter the data either by typing it in or cut and paste from another source. Be mindful of the header row to make sure if you have headers, the headers are pasted into the header row.
- Columns can be inserted or deleted by right clicking on the title row
- Once completed, give the table a meaningful name by entering a title in the 'Name' box and then click 'OK'.
- You'll now see the table listed in the queries pane of the PowerQuery window. In the table preview window will be the data you previously entered
- The query will also have a single step associated with it in the Query Settings pane (on the right) titled 'Source'.
Top tip!!
If you wish to edit the data previously entered, double click on the 'Source' step to re-open the 'Create Table' window where you can amend the existing data or add additional rows, columns or cells.
- Notice that the data types default to Text format even though the values entered are clearly numbers. If you try and apply any functions to these columns they'll be treated as text and could return an error if the expectation that they're numbers
- To change the formatting, click on the 'abc' icon in the title bar and change the formatting to the required type or select both columns and then in the ribbon under 'Transform' select 'Detect Data Type'
- Once the format is changed on each column, the following changes can be observed
- the icon next to the columns changes from 'abc' to '123',
- the contents of the cells in the preview window change to Italic formatting
- Cell formatting also changes from left justified to right justified
- An additional step is listed in the 'applied steps' pane and the formula associated with the step can be seen in the formula bar (Table.TransformColumnTypes with the associated arguments,
- https://docs.microsoft.com/en-us/powerquery-m/table-transformcolumntypes
The M language code that has been created by PowerQuery can be seen by clicking the 'advanced editor' button in the ribbon
Here you can see the code generated to replicate the table is made up of a number of M functions. Fortunately, there is no need to understand this code as the visual interface takes care of all the coding.
Comments
Post a Comment