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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Diego-mx
Advocate I
Advocate I

Calculated Tables with M language

Hello, 
I recently started using PowerBI.  I come from R and I have found the modelling capabilities very nice.  
In this occasion, I want to  create Calculated Tables using R scripts.  Either that, or calling data sources within the R transform in the Query Editor.  I haven't found the way to do it.  I have only been able to use the R scripts on new data sources.  

For example, 

I am connecting to a database and calling a table Cars.  
Then I want to create a new table called Inventory Weekly based on Cars with an R script.   

And then I can create a PowerBI visual from the result of that.  

 

I see three solutions: 

1. The preferred solution is the one I need most help with:  call the Cars datasource and modify it in an R script.  Thus creating Inventory Weekly but keep Cars source independent. 

2. I can manage to create a new source in which Cars is recalled and modified to target Inventory Weekly, with an R script.   
The problem with this is that I have to load Cars twice as a source, and I'd rather just build on top of it. 

3. Attempt to translate R code to DAX, so that I can modify this in place, as I've found is the recommended way to do it.  This is the best long term solution, but doesn't adjust to my present needs because there's a steep learning curve with DAX. 

 

Thanks 

 

 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

Create your Cars query. Create another query that references that query. You can then insert an R script step into your second query.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Diego-mx,

 

It would be easy like below. Then you can apply R after that.

let
    Source = DimProduct
in
    Source

Calculated_Tables_with_M_language

 

Best Regards,

Dale

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

View solution in original post

3 REPLIES 3
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @Diego-mx,

 

It would be easy like below. Then you can apply R after that.

let
    Source = DimProduct
in
    Source

Calculated_Tables_with_M_language

 

Best Regards,

Dale

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

Thanks.  That wasn't that hard.  😃 

Actually, I feel too much of a newbie with such simple solution, ha.  



Greg_Deckler
Community Champion
Community Champion

Create your Cars query. Create another query that references that query. You can then insert an R script step into your second query.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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