Overview
Crelate offers powerful reporting capabilities within the application today, but it is also possible to leverage Crelate’s API in a separate BI tool to get even more out of your data.
This guide will show you how to leverage Crelate’s latest API in Microsoft Power BI. The endpoints that can be used for reporting use the GET HTTP verb. For clients requiring technical assistance or full configuration, our Professional Services team can be contracted for setup & support. Connect with us here for more details.
You can read more about Crelate’s general API capabilities here.
Getting Started
To use these features your organization must already have access to Crelate’s API which requires a License SKU of Business or higher. In order to connect and retrieve data you will need to first generate an API Key. This key should be considered sensitive as it will grant callers access to any data the key owner has access to.
Connecting
To start getting data we must create a query connection -
In the Data group, expand Get data.
Select Web and a dialog will open.
Choose the Advanced option.
Specify the GET endpoint you are trying to hit (e.g., https://app.crelate.com/api3/contacts).
In the HTTP request header parameters section, add the parameter “x-api-key” and specify your API Key as its value.
Click OK.
Table Transformation
After the initial retrieve is done you should see some columns (Data, Metadata, Errors). This initial format is not immediately usable for reporting, so we need to do additional transformation.
In the Data column, click on the word “List” to drill down to a list of records.
In the Convert group, click To Table.
Keep the default values of “None” as the Delimiter and “Show as errors” for How to handle extra columns.
Click OK.
To expand the records further, click the expander icon in the header cell for Column1.
A pop up will appear that asks which columns you want, so choose what you need. You should only select the columns you intend to use as including more columns will increase the size of the download and how long it takes. Also, you probably want to uncheck Use original column name as prefix to reduce the noise on the column names.
Click OK.
Adding a Basic Chart
Now that the data is in a tabular format, we can display it in a report. We will get to columns that have “Record” as their cell value further down.
To use the data, you will need to Apply your query, which can be found in the Close group.
Navigate back to the Report View.
Over in the Visualizations pane, add a standard Table by clicking its icon.
To populate the chart with data, expand your query in the Data pane.
Select a few columns to populate the Table and drag them into Columns (e.g., ContactNum, LastName, ModifiedOn).
We can further refine the chart by applying local filters (e.g., top 20), sorting (e.g., ModifiedOn desc), titles, etc. by using the Filters pane and options in the Visual Editor.
Expanding Concepts
While we were able to add a basic chart, there is more we can do with the data returned from API 3. Let’s broaden into some additional concepts.
Special Data Type Transforms
A few fields are returned from API 3 as objects and will be visualized as “Record” in the column’s cell.
These cannot be used without some additional handling.
Some of these types include –
Addresses
Education
Emails
Lookups
Phone Numbers
Position
URLs
To use these fields, simply –
Click the expander icon in the column’s header.
In this instance you may want to check Use original column name as prefix as the property names will most likely repeat for additional records which could lead to confusion.
Click OK.
The column’s object will then be separated into its properties and will be easier to use.
Manipulating Data with Custom Columns
We are not regulated to only using the data as-is from the API. Since the query is just a regular data source, we can utilize standard Power BI features to give more context to our data. A simple example is creating a custom date column to show a trend of record creation.
Click the Add Column tab in the Ribbon.
Click Custom Column in the General Group.
We are going to add a formula to populate our column which uses standard Power Query M syntax. This will format the UTC date as “Month Year” e.g., January 2024.
Date.MonthName(DateTime.From([CreatedOn])) & " " & Text.From((Date.Year(DateTime.From([CreatedOn]))))
After we have our new column, we can apply it to the query and switch back to Report View.
Add a standard Stacked Column Chart by clicking its icon.
Now make the X-axis our new custom column “Create Date” and the Y-axis should just be “Count of Id”. This will show how many records were created in a month/year combo. However, the dates will not be in chronological order at first.
Next, add the standard CreatedOn field to the Tooltips section. This will allow you to sort the chart on its value.
Click the More options menu (ellipsis top right of chart) and expand Sort axis.
Select “First CreatedOn” and “Sort ascending”.
After applying the changes, the chart should then display left to right in chronological order with each column totaling the number of records created in that month/year combo.
Advanced Concepts
Now that we have a handle on the basics of connecting, retrieving data, transforming simple types, and adding columns, let us delve into a few more advanced concepts.
Paging Data
Retrieving large amounts of data is possible through Crelate’s API but the process requires you to page that data in chunks.
All retrieve endpoints that return a list of records support pagination through querystring parameters. This is handled by offset (number of records to offset the retrieve by – this is 0 based) and limit (how many records to return per page, default is 50, max is 100).
Paging takes some additional setup to get working within Power BI. Follow this process –
Create a connection to a data source as we have done before, like Contacts.
Once you have the base data you want, click Advanced Editor in the Query group.
You will need to add a snippet of code above the “let” in the query to convert the query into a function. This will instruct Power BI to pass in a variable called “PageStart” that will then be used as the offset in the URL. Follow the example below (note that the limit has been increased to the max 100 here too) –
Click Done.
Now you will probably want to rename the function in the Query Settings pane so you can easily refer to it later e.g., “fxContacts”.
We then need to create a separate query where we will invoke this function. Right-click in the Queries pane and select New Query -> Blank Query.
A blank query will then open. We are going to use this as the basis for our offsets so we will initially populate it with a list of values from 0 to 900 using {0..900} as the formula. Press Enter to populate the list. This will essentially give us the first 10 pages. This is only an example as you can use other queries to give you a more dynamic range instead.
Once you have the entire list, you will need to convert the List into a Table.
We cannot use this table as-is because it would cause a great degree of duplicate records to be returned – we must first trim it down to only the offsets that will yield unique pages.
We need to add a new Modulo column to aid with this. Click the Add Column tab in the Ribbon Bar and go to Standard -> Modulo in the Number group.
Specify 100 as the Value of the Modulo. This is because we are using 100 as our page size.
We then need to filter the table to only show values that have a remainder of 0, so select that number to filter down the first column.
Click OK.
Now that the Modulo filtering has cut down our first column to only the unique page offsets, we can remove the Modulo column.
Since we are creating a table of PageStart values, we need to convert the values from numbers to text.
To do this, right-click the first column and go to Change Type -> Text.
It is probably also a good idea to rename the first column to something like “PageStart” to make its usage more obvious.
Now it is time to get the data by page. To start this process, click Invoke Custom Function while on the Add Column tab in the query we have been working in.
This will open a dialog asking which function to invoke and which variable to use. We want to invoke our “fxContacts” function and use the “PageStart” column as the “PageStart” variable.
Once this runs you will see several tables bound by offset. Some of these entries will display “Error” if the page is blank. We will correct that next.
Right-click the “fxContacts” column and choose Replace Errors.
You want to replace the missing tables with lowercase “null” as seen below to essentially blank out these pages. We have to do this because in our example we are always retrieving 10 pages.
After this is done, you can expand fxContacts like we have done previously and it will expand out into usable tabular data.
Dealing with Lists
A few fields are returned from API 3 as object arrays and will be visualized as “List” in the column’s cell.
These cannot be used without some additional handling.
Some of these types include –
Multi-Lookups
Owners
Unfortunately, expanding the column as we did for the other “Record” objects will only give you the first element of the array. We will need to use a different approach.
We can aggregate the values of a List by utilizing a Custom Column with a formula, so let’s add another Custom Column. Follow the steps outlined above.
The example formula used here is basic but takes all the Title values of the Owners List and collapses it in a single comma delimited string. It is important to note that you should handle nulls otherwise the column will display an error. In this case we just show the text “None” if the value is null. Depending on your data you may want to alphabetize it, truncate it, change the delimiter, etc.
if [Owners] = null
then "None"
else Text.Combine(List.Transform
([Owners],
each Text.From(Record.Field(_, "Title"))
),
", "
)The list will then be visualized as a comma delimited string in the new column.
This column can then be used like any other column in a chart. This example shows Contact Ownership by people or group of people.
Cross Entity Queries
There are times when you need to show data from multiple entities at once or need it for filtering purposes. Power BI supports this through multiple queries and merging.
For our example we will show the human readable status name instead of the underlying integer value.
You can add another source of data with the Query Editor by click New Source in the New Query Group.
Select Web and you will see the connection dialog as before. This time we want to hit the https://app.crelate.com/api3/contacts/info endpoint which will give us Metadata about Contacts.
You may see a dialog like this, Anonymous access is fine because the Header will contain the API Key. Click Connect.
Unfortunately, when the data comes back Power BI will automatically expand it into something that is not that useful for our scenario. We will need to trim things down by rewinding the Applied Steps.
Right-click the “Expanded Data” step and select Delete Until End. This will remove everything after the initial table conversion, and we can drill down to only the bits of data we care about.
Once we only have the baseline table, we will work our way down to the EntityStatus List.
Drill down into Record in Data.
Drill down into Record in Fields.
Drill down into the EntityStatus field.
Click into List under Statuses.
Convert the List into a Table.
Expand Column1.
You should now see the Entity Statuses.
Your Applied Steps should look something like this –
Now that we have the list of Statuses, we can combine it with our previous Contacts query and get the Status Name per Contact.
Swap the query to the Contacts query in the Queries pane. This is important as we want to use Contacts as our base.
Click Merge Queries in the Combine Group.
A dialog will open that will ask you to select the columns that map up. For Contacts this will be EntityStatus. For Info this will be Value.
Make sure to select the correct Info query from the dropdown.
Once you have both columns selected, click OK.
This will add a new Table column to the Contacts query.
Use the expander to expand the Table and select the “Name” property.
You may want to rename the column to something like “Status”.
Once this is done you can apply the query and use the column in a chart. The example here shows Contacts in the system by Status –