Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Now we will explain how you can represent data through the Power BI software using a REST API created in the onesait Platform.

To do this, we created an API that gets the information stored in the Ontology HelsinkiPopulation, where the evolution of the population in the Helsinki city through time is stored.

Firstly, in Power BI, you must specify that the data will arrive through a web service. To do this, you must select the option Web in the menu offering the option Obtain Data.

Image Removed

If you want to use a REST API as your data source, you must configure the advanced options in the menu that just opened. There, in the field URL Parts, you must insert the url ENDPOINT BASE of the API you want to use (You can find it in the configuration of the API to be used in the platform).

Image Removed

If the API to be used has several queries, this URL must also include the name of the query you want to use. For this example, we created a query called Get-Info, so that the url has this aspect:

...

Table of Contents

Introducción

Microsoft Power BI es una herramienta de visualización y análisis de datos que permite crear visualizaciones de forma visual, permite utilizar fuentes de datos como CSV, bases de datos y como es el caso e incluso APIs Rest.

A continuación explicaremos:

  • Cómo usar un API REST como fuente de datos para importar datos JSON en Power BI

  • Cómo transformar los datos JSON en un formato tabular.

  • Cómo hacer una visualización utilizando los datos importados.

Paso 1: Instalar Power BI

Lo primero será instalar Power BI, en el ejemplo usaremos Power BI Desktop que es gratuito y nos permite crear visualizaciones en un entorno desktop (sin publicación a web).st elink:

Puedo descargarlo desde Microsoft Store o desde esta url: https://powerbi.microsoft.com/es-es/desktop/.

...

Paso 2: Identificar el API REST de la que traeré los datos

En el ejemplo usaremos un API pública del Entorno CloudLab de Onesait Platform.

Si no tenemos cuenta, puedo crear un usuario desde https://lab.onesaitplatform.com/ en la opción SIGN UP:

 

...

Una vez logado puedo acceder a mi entorno en el que si no he creado ningún elemento de plataforma veré una pantalla inicial como esta:

...

Lo que me interesa es buscar un API REST con información que pueda pintar en PowerBI, para eso accedo a la opción DEVELOPMENT>My REST APIs:

...

Ahí seleccionaré alguna de las APIs a las que tengo acceso, por ejemplo puedo buscar el API con información sobre los Restaurantes en New York:

...

Lo primero que haré será invocar el API para comprobar que datos devuelve y su estructura, para eso primero voy a la opción User Tokens y copio mi Token

...

Y luego voy a la opción Swagger del API seleccionada:

...

Vemos que el API sólo tiene un método GET que me devuelve todos los restaurantes:

...

Voy al método y selecciono Try it out, copiaré mi Token y pulsaré Execute:

 

...

Al ejecutarlo podré ver la estructura de cada Restaurante en el array recibido:

...

Que es esta:

...

Paso 3: Importar datos desde el API REST

Ahora abriremos Power BI, e iremos a la opción Obtener Datos> Web

 

...

En la parte de URL copiaré la URL de mi API REST ( https://lab.onesaitplatform.com/api-manager/server/api/v1/

...

Next, you must specify the mandatory fields to access the API. In this case, this is the user's token. To get a token, you only have to go to the platform, access the module My APIs and, in the API list, select the option User Token, in the upper right part Image Removed, once there, the needed token will appear (and, should there be none, you only have to select the option Generate Token).

Image Removed

All the needed information appears now like this:

Image Removed

Once the query has been executed through the API, and the data have been obtained, you must specify the data format. Start by specifying that the received data were in JSON format by right-clicking on the received package.

Image Removed

then, to extract the information coming from the API, you must select the option To the table, seen when you right-click on the field list,

Image Removed

then on the icon Image Removed several times, until the data have been completely deployed.

An important step before using the data is making sure that the data is correctly formatted. In this case, for instance, the different population and year fields are defined as text, so it would be interesting changing this format to number. This can be achieved by clicking on the following iconImage Removed

then selecting the right option, in this case Integer.

Changing the column names would also be useful. To do this, you must right-click on the column name, then select Change name, leaving the information like this:

Image RemovedTo use the data obtained through the API, you must select the option Apply in the tab File (or directly in the option Close and Apply to do this, then close the window).

Image RemovedOnce the data are obtained, the next step is creating visualizations from them. Firstly, you can create a graph representing the Helsinki population evolving through the years. To do this, select a Line graph by clicking on the following icon:

Image Removed

then select the fields you want to show, in this case Year and Population:

Image Removed

giving the following graph as the result:

Image RemovedThis representation can be in turn edited or completed with the options in the tab Format, allowing you to title the axis, use a grid, configure the legend, among many other options:

Image RemovedIn the Analytics tabs you can also show some analytic values such as a line representing the mean value of the population:

Image Removed

or a yellow line showing the median, giving this image:

Image Removed

In this simple way, an analyst can get useful information thanks to the API created in the platform.

If you want to get more value from the data obtained through the API, for this example, you can create a line and bar graph representing on one side the male and female population, and on the other the total population, selecting the icon of this kind of graph Image Removed and giving the right configuration to get results such as:

Image Removed

In short, this tutorial has taught you how to use the graph representation tool Power BI to represent information provided by a REST API created in the onesait Platform, and to get results such as those shown next.

...

Restaurants%20API ) indicando Uso avanzado:

...

Como cabecera HTTP pondré

accept: application/json

X-OP-APIKey: <mytoken>

Quedando al final:

...

Seleccionaré Aceptar y Conectar en la siguiente pantalla.

Tras esto Power BI abrirá el Query Editor presentándome el JSON importado desde la llamada al API REST en un formato tabular, como podemos ver en la imagen:

...

Si vamos navegando por el slide podemos ver todos los campos de cada elemento JSON:

...

Y si pinchamos sobre un elemento me dará la info completa:

...

Podemos ver que el atributo Restaurant.grades es una List, si pinchamos sobre ella en la tabla accedemos a los elementos:

...

Y si pincho sobre el elemento Record el detalle:

...

Para volver a la tabla original en la ventana de PASOS APLICADOS elimino los últimos pasos:

...

Paso 4: Convertir datos importados en una Pivot Table

Para crear una visualización, es mejor convertir los datos importados en una Tabla.

Para eso voy a PASOS APLICADOS y me sitúo en el primer elemento Origen:

...

Me aparecerá la opción Convertir a Tabla que seleccionaré:

...

Seleccionaré Aceptar:

 

...

Ahora quiero que mi tabla tenga varias columnas, para los campos del JSON, para eso usaré el botón que aparece a la derecha:

...

Seleccionaré todas:

...

Y luego volveré a hacer lo mismo sobre el atributo complejo Restaurant:

...

Haré lo mismo para Column1.Restaurante.address y Column1.Restaurants.grades:

...

Ahora ya estoy viendo todos los atributos que me interesan…así que puedo pulsar en Cerrar Y Aplicar:

...

 Tras esto tendré cargada la Tabla en mi modelo y puedo ver mis columnas:

...

Paso 5: Crear una visualización en la Vista Visualización

Una vez hemos transformado los datos en una tabla con el Editor de Consultas de Power BI podemos crear una visualización.

Vamos a crear diferentes tipos de visualización:

Empecemos por el gráfico de columnas agrupadas,

...

al seleccionarlo se me incluirá una visualización en mi paleta y podré configurar los campos a visualizar arrastrándolos a los diferentes componentes. Por ejemplo en Legend puedo arrastras Column1.Restaurant.cuisine y en Legend al arrastrar el campo _id me aparecerá como Recuento:

...

Ahora seleccionaré otro componente como un gráfico circular, en este caso con las valoraciones:

...