Refresh All Your Power BI Datasets with Python

BI Elite
28 Jan 202010:25

Summary

TLDREste video muestra cómo actualizar todos los conjuntos de datos de Power BI en todos los espacios de trabajo con un solo clic de botón, utilizando un script de Python en segundo plano. El proceso implica conectarse a la API de Power BI, obtener todos los espacios de trabajo y conjuntos de datos y lanzar una actualización para cada uno. Para ejecutar el script, es necesario instalar Python, registrar una aplicación en Power BI y conceder permisos en Azure Portal. El script requiere la instalación de pandas y matplotlib para funcionar en Power BI. Finalmente, el script devuelve un marco de datos vacío para satisfacer los requisitos de Power BI.

Takeaways

  • 🚀 Para actualizar todos los conjuntos de datos de Power BI en todos los espacios de trabajo con un solo clic, se ejecuta un script de Python en segundo plano.
  • 🔗 El script de Python se puede copiar y pegar desde el blog post que acompaña este video.
  • 💻 Para ejecutar el script, es necesario tener Python instalado en su máquina.
  • 🔧 El primer paso es registrar una aplicación en Power BI con el tipo de aplicación nativa y obtener un ID de cliente.
  • 🔓 En el portal de Azure, se deben conceder permisos de API para la aplicación registrada.
  • 🔑 El script requiere su ID de cliente, correo electrónico y contraseña de Power BI para la autenticación.
  • 🛠️ El script hace varias solicitudes a la API de Power BI para obtener workspaces, datasets y ejecutar actualizaciones.
  • 📈 Se utiliza una estructura de datos de Pandas para satisfacer la necesidad de Power BI de devolver algún tipo de datos en el script.
  • 🔄 El script actualiza todos los conjuntos de datos en todos los espacios de trabajo a los que tiene acceso.
  • 🔌 Para ejecutar Python en Power BI Service en modo personal, se requiere una puerta de enlace de Power BI en su computadora.
  • 📅 Ten en cuenta que cada actualización a través de la API de Power BI utiliza uno de sus actualizaciones programadas diarias.

Q & A

  • ¿Qué es lo que Parker muestra en el video?

    -Parker muestra cómo actualizar todos los conjuntos de datos de Power BI en todos los espacios de trabajo con un solo clic de botón, utilizando un script de Python en segundo plano.

  • ¿Cómo se puede copiar el script de Python mostrado en el video?

    -Puedes ir al blog post que acompaña este video y copiar el código directamente de allí.

  • ¿Qué hace el script de Python en Power BI?

    -El script de Python se conecta a la API de Power BI, obtiene todos los espacios de trabajo y los conjuntos de datos asociados, y luego inicia una actualización para cada conjunto de datos.

  • ¿Qué es la primera herramienta que debes usar para ejecutar el script de Python?

    -La primera herramienta que debes usar es la herramienta de registro de la API de Power BI, que puedes encontrar en dev.powerbi.com/apps.

  • ¿Qué tipo de aplicación debes seleccionar al registrar la aplicación en la herramienta de registro de la API?

    -Debes seleccionar el tipo de aplicación nativa (native) en lugar de aplicación web del lado del servidor (server-side web application).

  • ¿Qué permisos son necesarios para la aplicación en Azure Portal?

    -Necesitas permisos para leer todos los espacios de trabajo y leer y escribir todos los conjuntos de datos a través de la API.

  • ¿Cómo autenticarse con la API de Power BI?

    -Necesitas insertar tu ID de cliente, correo electrónico de Power BI y contraseña para autenticarte con la API y obtener un token de acceso.

  • ¿Qué librerías son necesarias para ejecutar el script de Python en Power BI?

    -Necesitas importar las librerías 'requests', 'json' y 'pandas'. Las primeras dos vienen por defecto en Python, mientras que 'pandas' necesita ser instalada previamente en tu máquina.

  • ¿Qué sucede si necesitas ejecutar Python en Power BI Service en modo personal?

    -Necesitarás instalar la puerta de enlace de datos de Power BI en modo personal en tu computadora, ya que actualmente no hay otra forma de ejecutar Python en Power BI Service fuera de través de una puerta de enlace personal.

  • ¿Cómo se ve afectado el límite de actualizaciones diarias de Power BI con esta técnica?

    -Cada actualización iniciada a través de la API de Power BI utiliza uno de tus límites diarios de actualización, por lo que debes tener en cuenta este límite al utilizar esta técnica.

  • ¿Cómo se puede ver el resultado final de la actualización de conjuntos de datos en Power BI?

    -Después de aplicar y ejecutar el script de Python en Power BI, se actualizarán todos los conjuntos de datos en los espacios de trabajo. Puedes verificar que se hayan actualizado visitando cualquier espacio de trabajo y verificando los conjuntos de datos.

Outlines

00:00

🚀 Actualización de conjuntos de datos de Power BI con un solo clic

Este párrafo presenta una guía para actualizar todos los conjuntos de datos de Power BI en todos los espacios de trabajo mediante un solo clic. Se discute la ejecución de un script de Python en segundo plano que actualiza los conjuntos de datos. El video muestra un ejemplo práctico de cómo funciona el proceso y se menciona la necesidad de instalar Python en la máquina para ejecutar el script. Además, se destaca la importancia de conectarse a la API de Power BI y se menciona un script de autenticación útil encontrada en la comunidad de Power BI.

05:03

🛠 Configuración y ejecución del script de Python en Power BI

Este segmento detalla los pasos para configurar y ejecutar el script de Python en Power BI. Se explica la necesidad de registrar una aplicación en Power BI para obtener un ID de cliente, conceder permisos de API y autenticarse con la cuenta de Power BI. Se mencionan las bibliotecas necesarias para el script, como requests, json y pandas, y se aclaran los cambios necesarios en el código para insertar credenciales y ejecutar la actualización de los conjuntos de datos. Finalmente, se describe cómo integrar el script en Power BI y su publicación en el servicio de Power BI.

10:03

📅 Manejo de actualizaciones y limitaciones diarias en Power BI

Este párrafo finaliza el video discutiendo la necesidad de un gateway de Power BI en modo personal para ejecutar scripts de Python en Power BI Service. Se menciona la limitación de ocho actualizaciones diarias y cómo el script utiliza una de estas. Además, se sugiere una estrategia para mantener los conjuntos de datos actualizados combinando actualizaciones programadas y manuales. El video termina con una recomendación para visitar el blog de BI Elite para obtener más información y consejos útiles sobre Power BI.

Mindmap

Keywords

💡Power BI

Power BI es una herramienta de visualización de datos y análisis desarrollada por Microsoft que permite a los usuarios crear informes interactivos y dashboards. En el video, se utiliza Power BI para mostrar cómo actualizar conjuntos de datos a través de diferentes workspaces utilizando un script de Python, lo que demuestra la capacidad de integración y automatización de Power BI con otras herramientas de programación.

💡Python script

Un script de Python es un conjunto de instrucciones escritas en el lenguaje de programación Python que se ejecutan de manera secuencial para realizar una tarea específica. En el contexto del video, el script de Python se utiliza para conectarse a la API de Power BI y actualizar todos los conjuntos de datos en todos los workspaces a los que el usuario tiene acceso.

💡Workspaces

En Power BI, los workspaces son áreas donde los usuarios pueden colaborar y compartir informes y dashboards. Son similares a carpetas que contienen conjuntos de datos, informes y paneles. El video muestra cómo utilizar un script de Python para actualizar conjuntos de datos en múltiples workspaces, lo que demuestra una aplicación práctica de la automatización en un entorno colaborativo.

💡Datasets

Los conjuntos de datos en Power BI son colecciones de datos que se utilizan para crear visualizaciones y análisis en informes y dashboards. Los conjuntos de datos pueden ser actualizados periódicamente para reflejar información actualizada. El video trata sobre cómo actualizar todos los conjuntos de datos en todos los workspaces a través de un script de Python, lo que es útil para mantener los informes actualizados.

💡API (Application Programming Interface)

Una API es un conjunto de rutinas y protocolos que permiten que softwares distintos se comuniquen entre sí. En el video, se utiliza la API de Power BI para permitir que el script de Python se conecte y realice acciones en el servicio, como actualizar conjuntos de datos. La API es fundamental para la integración y automatización de tareas en diferentes plataformas.

💡Refresh

Actualizar (refresh) en el contexto de Power BI se refiere al proceso de traer nuevos datos o actualizados a los conjuntos de datos para mantener los informes y análisis actualizados. El video muestra cómo utilizar un script de Python para actualizar automáticamente todos los conjuntos de datos en lugar de actualizarlos individualmente, lo que ahorra tiempo y esfuerzo.

💡Single button click

Un clic en un botón simple es una forma de interactuar con una aplicación o sistema informático que desencadena una acción o serie de acciones predefinidas. En el video, este concepto se refiere a la facilidad con la que los usuarios pueden actualizar todos sus conjuntos de datos en Power BI con solo un clic, gracias al script de Python que han configurado.

💡Blog post

Un blog post es una entrada o artículo escrito y publicado en una plataforma de blogging que trata un tema específico. En el video, el presentador menciona un blog post que acompaña el contenido del video, donde los usuarios pueden encontrar más información y el script de Python que se utiliza para actualizar conjuntos de datos en Power BI.

💡Azure portal

El Azure portal es una plataforma en línea que proporciona una interfaz de usuario para administrar y configurar servicios de Microsoft Azure. En el video, se menciona el Azure portal como el lugar donde los usuarios pueden conceder permisos de API para su aplicación Power BI, lo que es esencial para que el script de Python funcione correctamente.

💡Client ID

El ID de cliente (Client ID) es un identificador único que se utiliza para autenticar una aplicación cuando se conecta a un servicio de API, como la API de Power BI. Es una parte crucial en el proceso de autenticación y autorización, permitiendo que el script de Python identifique y se comunique con la API de manera segura.

💡Personal gateway

Una puerta de enlace personal (personal gateway) es una aplicación que se instala en un dispositivo local y permite a Power BI Service conectarse a orígenes de datos en el entorno local para la actualización de datos y otros procesos. En el video, se menciona que se necesita una puerta de enlace personal en modo personal (personal mode) instalada en el ordenador para ejecutar scripts de Python en Power BI Service.

Highlights

Parker demonstrates a method to refresh all Power BI datasets across workspaces using a single button click.

The process involves running a Python script in the background.

The Python script connects to the Power BI REST API to refresh datasets.

The script retrieves all workspaces and datasets, then initiates a refresh for each dataset.

To run the script, Python must be installed on the machine.

The Power BI API registration tool is used to create an application for API access.

API permissions for reading workspaces and datasets are required.

The Azure portal is used to grant admin consent for the API.

The script needs the client ID, Power BI email, and password for authentication.

An access token is obtained for API communication.

The script sends requests to the Power BI API to get workspaces and datasets.

A POST request is used to refresh each dataset.

Power BI requires a pandas dataframe in the script for data return.

The script returns an empty dataframe to satisfy Power BI's requirement.

The method can be used in conjunction with scheduled refreshes.

Power BI Personal Gateway is necessary for running Python in Power BI Service.

The video provides a time-saving solution for refreshing multiple datasets.

Transcripts

play00:00

what's up everybody its parker with VI

play00:02

elite i have an awesome video today

play00:04

showing you how to refresh all of your

play00:06

power bi datasets across all of your

play00:08

workspaces using a single button click

play00:11

this is going to run a python script in

play00:13

the background in order to refresh all

play00:15

these datasets so for example I have

play00:18

this workspace with a data set name to

play00:20

refresh all data sets python script if i

play00:22

click the refresh now' button you'll see

play00:24

after a few seconds once it kind of

play00:27

kicks in its going to refresh the other

play00:30

three data sets in my view here

play00:32

so now we see they're starting to

play00:34

refresh and they're successfully

play00:36

refreshed at 8:32 a.m. but the even

play00:39

cooler idea here is i can go to all my

play00:41

other workspaces like another workspace

play00:43

and check out my data sets and you can

play00:45

see these data sets were refreshed as

play00:47

well so this is gonna refresh all of

play00:50

your data sets across all of the

play00:52

workspaces that you have access to so

play00:54

this is an amazing trick and i'm gonna

play00:55

show you how you can do in just a few

play00:57

steps so the first thing you need to

play00:59

understand about this trick is it's

play01:01

running a python script

play01:02

here's that python script if you want to

play01:04

be able to just copy and paste this into

play01:06

your own editor you can go ahead and

play01:08

navigate over to the blog post

play01:09

accompanying this video and copy it

play01:12

directly from there so we'll get into

play01:14

this code a little bit later but

play01:17

basically what it's doing is it's

play01:18

connecting to the power bi rest api

play01:21

once it oughtn't Achatz it gets all of

play01:24

the workspaces that you were a part of

play01:26

and then all the data the data sets of

play01:29

all of those workspaces and kicks off a

play01:31

refresh for each one of those data sets

play01:33

but we'll get into that a little bit

play01:34

later so the first step in order to be

play01:36

able to run this python script is

play01:38

firstly installing python on your

play01:40

machine i have another video showing you

play01:43

how to install and run python scripts in

play01:46

power bi so make sure you check out the

play01:48

video I'll link it down in the

play01:49

description as well so the first step

play01:51

that we need to accomplish here in this

play01:54

video is we need to go to the power bi

play01:58

API registration tool so you can find it

play02:01

at this link dev power bi comm slash

play02:03

apps and basically it's a two step

play02:05

process the first step is simply signing

play02:07

in to power bi I've already done that

play02:09

and the second step is registering your

play02:11

applicant

play02:13

so you firstly need to name your

play02:15

application a name line refresh all

play02:17

datasets and then this is very important

play02:19

make sure you select the native

play02:21

application type instead of server-side

play02:23

web application you need to select

play02:25

native and once you do so you just need

play02:27

to provide a couple of API accesses we

play02:30

only need to read all workspaces and

play02:32

read and write all data set API accesses

play02:36

once you do that click register and it's

play02:38

going to create basically an application

play02:42

or client ID so when that happens make

play02:45

sure you save that I'm not actually

play02:46

going to do that I've already done that

play02:47

but save that application ID because

play02:50

you're going to need to copy and paste

play02:51

it into your code the next thing you

play02:53

need to do is navigate over to your

play02:55

Azure portal where you can grant your

play02:58

permissions for the API so just starting

play03:02

from the home page if you search for app

play03:05

registrations so navigate there and

play03:08

select your application that we just set

play03:10

up so refresh all data sets and on the

play03:13

left side there's an API permissions and

play03:16

click this grant admin consent button

play03:20

and it's gonna grant admin consent to be

play03:22

used by your Python script do that and

play03:24

your Python script will run flawlessly

play03:27

so now open up a code editor take this

play03:30

code that I've already read and so again

play03:32

go over to the blog copy this code and

play03:34

you're going to need need to change just

play03:37

a couple of lines so you are going to

play03:39

insert your client ID the one you just

play03:42

got from that registration tool you're

play03:44

gonna insert your power bi email and and

play03:46

you're gonna insert it in your power bi

play03:48

password these are necessary in order to

play03:49

authenticate with that power bi API so

play03:53

once you authenticate it's going to

play03:55

grant you an access token and I do want

play03:57

to say real quick I didn't write all of

play03:59

this code for the authentication I found

play04:01

this on a on a post on the power bi

play04:05

community so props to the person that

play04:07

wrote this code to authenticate I think

play04:09

I've seen this around a couple of times

play04:10

but it's very useful so once you get

play04:12

that access token you then need to make

play04:15

a series of requests to the power bi API

play04:18

so the first request is going to get all

play04:20

of your groups or workspaces so

play04:22

basically using this power bi

play04:25

end point to get your groups you're

play04:27

gonna send that groups request they're

play04:29

gonna come back in a kind of walkie

play04:31

format but I'm using some logic to turn

play04:34

it into the proper formatting in order

play04:36

to get the information that we need I'm

play04:38

not gonna walk through all of these

play04:39

lines or all this logic but if you need

play04:41

some more help kind of crunching through

play04:43

this Python make sure you send me a

play04:46

message over at BI elite comm slash

play04:49

contact and I can you can send me a

play04:51

message there and I'll reach back out to

play04:53

you so once we have all of our

play04:55

workspaces we're going to iterate

play04:57

through those workspaces and send

play04:59

another request to the power bi API in

play05:03

order to retrieve all the datasets that

play05:05

are that basically make up that

play05:08

workspace and once we have all of our

play05:10

datasets

play05:11

we're gonna iterate through each of

play05:12

those datasets and hit the power bi API

play05:15

one more time to send a refresh for that

play05:19

specific data set so as you can see just

play05:21

in this refresh you are all at URL line

play05:24

here we are sending a post request to

play05:27

the specific endpoint and you see that

play05:30

we're throwing in group and the dataset

play05:32

ID that we had received previously from

play05:35

those previous two calls so doing that

play05:37

we're able to kick off a refresh for

play05:39

each data set for each workspace that

play05:42

I'm a member of and finally I should

play05:45

note that the last line here it's

play05:47

basically saying final equals pandas

play05:49

dataframe this is only necessary because

play05:52

power bi running a powered Python script

play05:55

within power bi requires that a panda's

play05:57

data frame is present at least once in

play06:00

the script power bi needs a data frame

play06:03

to be returned in order to basically say

play06:05

this query returns some sort of data so

play06:08

this is just returning an empty data

play06:09

frame with no data but it satisfies

play06:11

power bi eyes need for some data in that

play06:14

Python script one more thing to note I'm

play06:18

importing for libraries here up top a

play06:21

dhow request JSON and pandas the first

play06:24

three are built into Python by default

play06:26

whereas pandas needs to be installed on

play06:29

your machine before this will work again

play06:32

that is covered over in my running

play06:34

Python scripts in power bi video you

play06:36

basically need to install both pandas

play06:38

matplotlib in order to run Python

play06:40

scripts at all in power bi so once you

play06:42

have this once you fill out these three

play06:44

lines up here client ID username and

play06:46

password go ahead and copy that into

play06:49

power bi so let's go ahead and navigate

play06:51

over to power bi and I have opened up

play06:55

the backend a power bi the query editor

play06:57

and I have created a new source with a

play07:00

Python script and simply pasted it in so

play07:03

here is my script and you see I still

play07:06

have those kind of dummy lines in so

play07:08

this won't work for me so I'm actually

play07:09

going to cancel out since I actually

play07:11

have my real credentials stored in there

play07:13

so cancel out or I'm gonna cancel out

play07:17

you click OK let it run once you once it

play07:20

runs select your final which is that

play07:23

empty pandas dataframe that came through

play07:24

and then finally it's gonna return an

play07:27

empty table but just close and apply and

play07:30

once we're back at our power bi report

play07:33

once it's applied those changes and run

play07:35

through that Python script it actually

play07:37

will have refreshed all of your datasets

play07:39

already since its kicked off that script

play07:41

but in order to kind of see this in its

play07:44

final working version I'm gonna go ahead

play07:45

and save it once you save it to publish

play07:49

it up to your power bi service portal

play07:51

you can publish this anywhere I've

play07:53

actually already published it to a

play07:55

workspace called refresh example

play07:57

so now I'd refresh example I'm going to

play08:00

navigate there refresh example so I am i

play08:04

refresh example now we're kind of back

play08:06

to the beginning

play08:07

once I click this refresh Now button as

play08:09

you know is going to refresh all of my

play08:11

datasets one thing you also need to know

play08:13

is that you do need a power bi gateway

play08:17

in personal mode installed on your

play08:19

computer as of right now

play08:21

there is no other way to run Python on

play08:24

power bi service unless it's through a

play08:26

personal gateway so just to show you I

play08:29

have my personal gateway on-premises

play08:31

data gateway personal mode already set

play08:34

up on my computer

play08:35

this is extremely necessary not very

play08:37

hard to do just go simply just Google

play08:41

for power bi personal mode gateway

play08:43

there's some documentation showing you

play08:44

how to set that up once you set that up

play08:47

it should run well you'll click this

play08:49

refresh Now button and you'll probably

play08:50

get one

play08:51

it's a one-time error saying you need to

play08:53

provide credentials for this Python

play08:55

script datasource

play08:56

simply click sign-in and it'll just go

play08:59

away and you'll be able to refresh as

play09:00

many times as you want so just as an one

play09:03

more example I'll click this refresh Now

play09:05

button give it a little bit of time and

play09:07

it's gonna kick off a refresh for every

play09:09

single other data set in all of my

play09:11

workspaces on my power bi portal so

play09:18

these are starting to kick off and

play09:19

finish you see this time has changed now

play09:21

as we've gone through this video and

play09:24

going back to our other workspace we see

play09:28

these are now updated as well so I

play09:30

really hope you like this video I'm

play09:32

gonna use this trick all the time in

play09:34

case I need to refresh all my data sets

play09:36

at once instead of going through each

play09:38

individual data set and clicking the

play09:40

refresh Now button this can be used in

play09:43

conjunction with the scheduled refresh

play09:45

as well just keep in mind that you only

play09:47

have eight refreshes per day so each one

play09:50

of these refreshes that we're kicking

play09:52

off via the power bi API is using one of

play09:55

your scheduled refreshes so in reality

play09:57

for my data sets if I need to keep them

play09:59

really up to date I'll probably do

play10:00

something like setting up six scheduled

play10:03

refreshes per day and still myself to

play10:06

click that button at least twice a day

play10:07

in order to refresh all my data sets so

play10:10

I really hope you like this trick make

play10:12

sure you check out the blog over at the

play10:13

bi elite blog has some really good stuff

play10:15

over there and a little bit more

play10:17

information on this trick so in case you

play10:19

like this video make sure you subscribe

play10:20

to the channel subscribe to the blog and

play10:22

I will see you with a next trick

Rate This

5.0 / 5 (0 votes)

関連タグ
Power BIPython ScriptActualización MasivaConexión APIWorkspacesEficienciaDatsetsProgramaciónInteligencia de Negocios
英語で要約が必要ですか?