Power Query: Binary Function
20 January 2021
Welcome to our Power Query blog. This week, I look at using a function when processing binary data.
I have some data for my salespeople. The data is in the form of a collection of Excel files held in one folder. I would like to create a custom function that I can run against this data before I combine the files into one query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image1.png/e774d10cbbb9450fc45efbe51abdf434.jpg)
I start in the ‘Get & Transform’ section of the Data tab, where I choose to create a ‘New Query’. From the dropdown, I can select ‘From File’ and then ‘From Folder’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image2.png/f32e5a15e2cf9c3e4d2d058458ce054d.jpg)
I select the folders location and view the files. I choose to ‘Transform Data’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image3.png/f1140ff857fc3b6f5f97a6a24f4a6fc7.jpg)
I right-click on the first value in the Content column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image4.png/72aa864d2854c6fefb1083fba0ab5792.jpg)
I am going to ‘Add as New Query’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image5.png/36776d1da4d05b45bb5a5d09375f407c.jpg)
This has created a new query which points at my first Excel file, that just happens to be Derek’s. I rename my query Sample_Expenses.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image6.png/23912d3b1671861e02bebcd5183f1607.jpg)
I create a new parameter from the Home tab.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image7.png/6f49c288a0d88a66b427eaf4ece923d6.jpg)
I call my new parameter Expense_Parameter, and once I choose type Binary. It finds the Sample_Expenses query, and allows me to select it as the default and current value.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image8.png/b9ee28d90e6b5bc92ea4aeafdad51628.jpg)
Once I have created Expense_Parameter, I can right-click it in the Query pane and create a Reference query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image9.png/0485ccbc83bdeec1d741bad442a1ea5f.jpg)
I call my new query Transform_Sample_Expenses.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image10.png/daf8c4f0259ce428269c0d3d4badd32b.jpg)
I can right-click on my new query and choose ‘Create Function’.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image11.png/22c6daeb82d7d69ac88f878227e04b28.jpg)
This function will be linked to my current query, Transform_Sample_Expenses. I call this function Transform_Expenses.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image12.png/a1537847463e660a31158c8032525438.jpg)
My function query expects a binary file as a parameter, and defaults to Derek’s expenses. I can now return to my Transform_Sample_Expenses and make some transformations.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image13.png/917da985be13220165c8d2823e95344f.jpg)
I need to treat my file as an Excel file, so I right-click on the file and choose Excel.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image14.png/8c3be7af9f73d031acae69ed85a2e148.jpg)
Since this is the format of all the files in my folder, I continue to transform my data.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image15.png/e63c0a4c21afc9afb438aacc09a59317.jpg)
I have removed the first row, expanded the table data, and removed the columns I don’t need. Finally, I fill down on the name. I ‘Close & Load’ from the File tab to save my query.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image16.png/d082e3477129350b8a2a589156028e63.jpg)
Back in the query for my Expense folder (‘Expenses Folder Custom’), I can add a column which will call the function I have created.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image17.png/a468c9c28195e8f18fdedfa59a0cf042.jpg)
I can select the Transform_Expenses function.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image18.png/61935f470d8b9f21b7b7683ffca40895.jpg)
I am then prompted to enter the binary parameter, and I choose the Content column.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image19.png/06909e3fbfc8faf87de7555c0b99e9d3.jpg)
Table data appears in my new column, and if I select one of the lower table values, I can see that I have transformed all of my Excel files, ready to be combined.
![](http://sumproduct-4634.kxcdn.com/img/containers/main/blog-pictures/2020/power-query/216/image20.png/173ef895b62ce391674d271b99c4d178.jpg)
I can expand the table data and remove the columns I don’t need.
Come back next time for more ways to use Power Query!