Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Store Power Query custom function Online (Github etc..,) and call it

Main Question :

I have created various custom functions that I frequently use. I would like to store them in a repository somewhere and call them whenever necessary. I know that I can save all those functions in an Excel file and save it in OneDrive. But I would like to save them somewhere I can edit and share them easily like GitHub.

And finally, if it is possible, can we make a private repository? If i want few of my functions to be shared privately, can I protect/lock them using a password?

Helpful Resources:

Understanding the following probably might be helpful in answering this.

Resource 1:

There is a function called #shared in PowerQuery which lists down all the functions available and their respective description. You can know more about it at the following post.

I think understanding how does this function (#shared) work and Where is this information being extracted from will be helpful in answering My main question above. Which is basically, how can I make something like this for my custom functions?

Resource 2:

One possible help for this question would be an existing repository in Github by Hugoberry.

Note:

  1. I'm not a coder, but I'm comfortable in reading/understanding codes.
  2. I don't understand Github very clearly.

Edit 1:

For those who are looking for an answer to this question, the answer provided by Nacho works for creating a function with Manual Entry(Text/Number) inputs.

It does not work for functions that refer to a table/parameter.

like image 219
Gangula Avatar asked Jul 27 '19 12:07

Gangula


1 Answers

After taking a long path on this I solved it. Below are the steps to do this:

  1. First create a .pq file with Notepad like this example and push it to GitHub:
let
    TextAsNumber = (valor as number)  => 
        let
            Mostra = "The number is: " & Text.From(valor)
        in

    Mostra
in
    TextAsNumber
  1. Then go to the file in github and click on "Raw"
    GitHub - Raw

  2. Copy the URL. Open Power Bi Desktop edit queries. Get Data from blank query and paste this:

= Expression.Evaluate(Text.FromBinary(Web.Contents("https://raw.githubusercontent.com/ibarrau/PowerBi-code/master/PowerQuery/PQFun.pq")),#shared)
  1. That code will create you the function from repository.

Note: The same thing can be made with local path too, just replace Web by File on "Contents". Like so:

= Expression.Evaluate(Text.FromBinary(File.Contents("C:\Users\username\Documents\Folder\Sub-Folder\PQFun.pq")),#shared)

Hope this helps you to manage better the custom function repository.

PS: I'm not sure if you are going to be able to refresh in Service.

like image 178
ibarrau Avatar answered Nov 04 '22 00:11

ibarrau