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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
fdanielsouza
Helper I
Helper I

How to convert row to dict using Python transform?

Hi, I noticed that when we use Python Transformation, then Power Query is aware of the row we are. If we do, for example, dataset[newcolumn] = dataset[somecolumn] it will give the corresponding row value to the new column. Problem is, when we do something like str(dataset[somecolumn]), Power Query loses his awarenesess of which row it is at, instead it'll probably raise an error, or if we do something to aggregate those values it will give the entire dataframe for each row. 

 

Question is: how can I get Power Query to know which row it is again after do some kind of conversion? 

2 REPLIES 2
Icey
Community Support
Community Support

Hi @fdanielsouza ,

 

I am not very sure what you want to do. Do you want to convert rows into columns?

If so, how about using UnPivot or Transpose?

 

transpose and unpivot.JPG

 

If not, could you share us more details?

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ImkeF
Community Champion
Community Champion

Hi @fdanielsouza ,
not sure what's actually going on in what you're describing.
But the "problem" with Power Query is that it uses some syntax sugar when working with functions.
Therefore, using square brackets can mean that you're referencing either a column from a table or a field from a record. The later would be "row aware".
So to understand what's (not) going on in your case, I would have to understand the context in which the expressions where used.
For more, see this link: Understanding Power Query M functions - PowerQuery M | Microsoft Docs 
and for the lookup operators: Operators - PowerQuery M | Microsoft Docs

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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