Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Using Python Instead of Measures

Hey all,

 

Here's some background: I'm very familiar with python pandas. Not so familiar with Power BI measures. It's been ok, but DAX coding just doesn't come so easily to me.

I have a simple question:

Has anyone seen or used python scripts used in a data model instead of having to create a bunch of measures? 

 

Best.

1 ACCEPTED SOLUTION

Hey @Anonymous ,

 

I would not consider it a shame, as DAX is a "query language", whereas python is a "general purpose" programming language of course with great data processing support eg. pandas, ... not to mention all the things possible if we are considering more advanced algorithms.

 

But DAX is designed to wade through billions, trillions of rows in real time, meaning a user changes the slicer selection.

 

Personally I'm / we are (at enterprise level) using python to create more "composed" visuals, where the composition is more important than the interactivity provided by the default visuals that are based on d3.js.

From an enterprise perspective we are not using python from within Power BI for data transformation directly, but of course python can be used together with Azure Databricks, providing tremendous possibilities 🙂

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

6 REPLIES 6
jratac
Frequent Visitor

Hi,

 

Just in case people are reading this thread and looking for potential solution, here's an article I found to create multiple measures in Power BI using Python: 

 

https://python.plainenglish.io/creating-multiple-measures-in-power-bi-using-python-7a8cf6e200dc

 

TomMartens
Super User
Super User

Hey,

 

basically you can't compare measures with using python, this is due to the fact that python can "just" be used

  1. as a data source, or from within power query to process data or
    (please be aware that pyhton (and also R scripts) require the personal gateway mode, if data has to be refreshed automatically, this may be impacted by compliance requirements, if you have to bow to enterprise requirements) 
  2. to a create a visual

In the 1st case the python script will just be executed on data refresh and not during user interactions like filtering data using slicers. Of course the viusal will adapt to other slicer slections.

 

A measure can be "reused" in various visuals, whereas a python script has to be used multiple times, meaning multiple scripts have to be maintained.

 

My recommendation, start using DAX and "just"use python, if DAX or M can't solve the problem.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

When using python to create a visual the data is dynamically calculated based upon your slicers. Is there a way to get the data from a python visual and show it in a table, so that table dynamically changes with the visual?

 

 

Hey,

 

currently it's not possible to pass data from a python or r script visual back to Power Bi so that the data from the visula can be used inside a table or matrix viusal.

 

But maybe this article will provide you with some ideas:

https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.table.html

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Anonymous
Not applicable

@TomMartens 

 

Much appreciated man. Great insight that you could tell I was doing this within my company. That's a shame about Python, and I'll need to commit to measure in DAX. In what instances would people use Python scripts within Power BI? For 1-off reports mostly?

 

Also, Hamburg is a great city, I lived there for 3 months in 2013. 

 

Best.

Hey @Anonymous ,

 

I would not consider it a shame, as DAX is a "query language", whereas python is a "general purpose" programming language of course with great data processing support eg. pandas, ... not to mention all the things possible if we are considering more advanced algorithms.

 

But DAX is designed to wade through billions, trillions of rows in real time, meaning a user changes the slicer selection.

 

Personally I'm / we are (at enterprise level) using python to create more "composed" visuals, where the composition is more important than the interactivity provided by the default visuals that are based on d3.js.

From an enterprise perspective we are not using python from within Power BI for data transformation directly, but of course python can be used together with Azure Databricks, providing tremendous possibilities 🙂

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.