Skip to main content

Posts

Showing posts with the label M

How to type or cut & paste data directly into PowerQuery / PowerBI

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

Use Power Query (M Language) to scrape a web page and output it to a CSV file

When using PowerQuery / M / PowerBI to scrape web pages, it's often useful to output the data to a CSV file. This enables the recording of multiple scrapes (with the time stamp in the filename) and also makes transformation and reloading more efficient. Below is a piece of M code I recently used to capture a webpage and record its details to a CSV file. This is a simplified piece of code to demonstrate the application, if there are additional transformations that are required, these can be done before the RScript line/step in the code. Click here to download the file in the this example let     Source = Web.BrowserContents("www.bbc.co.uk"),           #"Extracted Table From Html" = Html.Table(Source, {{"Column1", ".module--highlight .media__link"}, {"Column2", ".module--highlight .media__tag"}, {"Column3", ".module--highlight .block-link__overlay-link"}, {"Column4", ".module--hig