Difference between revisions of "Power BI with Power Query"

From Charitylog Manual
Jump to: navigation, search
(Creating a Queary)
(Creating a Queary)
Line 28: Line 28:
  
 
 
<code>let
+
<code>
 +
let
 
     APIHost = "https://api.dizions.co.uk/v2/",
 
     APIHost = "https://api.dizions.co.uk/v2/",
 
     URL = APIHost
 
     URL = APIHost
 
     & "clients/selectable_fields"
 
     & "clients/selectable_fields"
 
     & "?resolveIds[]=ALL",
 
     & "?resolveIds[]=ALL",
     apiResults = Json.Document(Web.Contents(URL, [Headers=[#"Source"="77fe25cc5a6b48c2d5fded3ad956110e38fa20fc", #"Org"="$2y$10$UpGLlfbd7w9cLyeTxN0D/us8ylNNoBnNt8Rf5znvdIxgDL/Zh6EZa", #"User"="$2y$10$fpBS.6gWp1G4BMNmDTlNJ.ehbx9x8WASNr0YD9dkXMAMyl.y0xLSG"]]))
+
     apiResults = Json.Document(Web.Contents(URL, [Headers=[#"Source"="Your_Source_Key", #"Org"="Your_Org_Key", #"User"="Your_User_Key"]]))
 
in
 
in
     apiResults</code>  
+
     apiResults
 +
</code>  
  
 
To access the Advanced editor click on the View Tab and select 'Advanced Editor'.  This will open a new window.  For the purpose of this example you can copy the text below but you will need to change the file path on the second line (keyFile) to the location of your [[API_Authentication#Using_Excel_to_store_credentials_for_Power_Query| Authentication File]].  In the advanced editor delete the details currently displayed and paste the text from the file below, making sure you have updated the keyFile line.
 
To access the Advanced editor click on the View Tab and select 'Advanced Editor'.  This will open a new window.  For the purpose of this example you can copy the text below but you will need to change the file path on the second line (keyFile) to the location of your [[API_Authentication#Using_Excel_to_store_credentials_for_Power_Query| Authentication File]].  In the advanced editor delete the details currently displayed and paste the text from the file below, making sure you have updated the keyFile line.

Revision as of 11:27, 18 November 2022

This section requires Power BI skills, developer skills and a knowledge of how an API works. It may be useful to use an API Development tool to check the dictionaries and make test calls, Postman is a suitable tool for this. Power Query is used to call the API to retrieve the data.

What you will need

In order to follow this section you will need the following;

  • Dizions API Licence (Read Only or Full)
  • Microsoft Power BI Professional licence
  • Power BI Desktop installed
  • API Development tool (Optional)

Creating a Queary

Here we are going to look at how to get started using the API and Power Query in Power BI.

Open Microsoft Power BI Desktop and select get data.

PowerBI-getdata.png

Power BI Desktop will then open and display the Get Data Menu. By default the All source menu will be selected. Scroll to the bottom of this list and select blank query and click Connect.

PowerBI-blankquery.png


This will open the Power Query Editor and create Query 1. On the menu ribbon in PowerBi Desktop select the advanced editor, to display the code editor.

PowerBI-AEribbon.png

In the advanced editor we are going to create a query to get the available fields from the client endpoint.


let

   APIHost = "https://api.dizions.co.uk/v2/",
   URL = APIHost
   & "clients/selectable_fields"
   & "?resolveIds[]=ALL",
   apiResults = Json.Document(Web.Contents(URL, [Headers=[#"Source"="Your_Source_Key", #"Org"="Your_Org_Key", #"User"="Your_User_Key"]]))

in

   apiResults

To access the Advanced editor click on the View Tab and select 'Advanced Editor'. This will open a new window. For the purpose of this example you can copy the text below but you will need to change the file path on the second line (keyFile) to the location of your Authentication File. In the advanced editor delete the details currently displayed and paste the text from the file below, making sure you have updated the keyFile line.

Referral Query Text

You will be prompted that Information is required for the data privacy. Click on continue. Click the check box to ignore privacy and select save.

The query will then run and display a preview table of referrals dated in 2020 with the following fields;

  • id - Case/Referral ID
  • date - The recorded date of the case/referral
  • client - This is the client (record) ID
  • referrer - This is the named referrer recorded.
  • contact_method - This is the contact method recorded when the case/referral was created.
  • client_age_range - This is the persons age range at the time of referral to the project.
  • project_name - This is the name of the project that the case/referral is recorded against.