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
didierjoc
Regular Visitor

Table gets empty when looping through a column

Hi everyone,

 

I have a question concerning the use of R to transform data in Power BI.

 

I am working on this table and trying to replace the first column data.

 

Data before

 

 

I have trouble understanding how does R code can really interact with data, and I am a beginner in R. This might be why I get this error :

 

I wrote this script (trying, as a test, to replace all values of the first column by 1) and when I run it, the data seems to be empty :


ctr <- 0

for (day in dataset[,1]) {
ctr <- ctr + 1
dataset[,1][ctr] <- 1
}

 

After R script

 

I thought someone may have a solution.

 

Thanks,

 

Baptiste

 

 

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @didierjoc,

In your R scrip, there are no result, so it returns empty table. I try to reproduce you scenario and get expected result.
The following is sample data, I replace the first column data to 1.

5.png
 
In the Power Query Editor, click the “Run R Scripts”, type the following script and click OK.

ctr <- 0for (day in dataset[,1]) {ctr <- ctr + 1 dataset[,1][ctr] <- 1}output<-dataset


7.png

 

 
Finally, click Apply&Close, you will get the expected result as the following screenshot.

8.PNG
 

If you have any other issue, please feel free to ask.

Best Regards,
Angelia

View solution in original post

2 REPLIES 2
v-huizhn-msft
Employee
Employee

Hi @didierjoc,

In your R scrip, there are no result, so it returns empty table. I try to reproduce you scenario and get expected result.
The following is sample data, I replace the first column data to 1.

5.png
 
In the Power Query Editor, click the “Run R Scripts”, type the following script and click OK.

ctr <- 0for (day in dataset[,1]) {ctr <- ctr + 1 dataset[,1][ctr] <- 1}output<-dataset


7.png

 

 
Finally, click Apply&Close, you will get the expected result as the following screenshot.

8.PNG
 

If you have any other issue, please feel free to ask.

Best Regards,
Angelia

Hi Angelia,

 

It works indeed, I didn't know I had to do so !

 

Thanks a lot !

 

Didier

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.