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

Get Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.

Reply
jkraush1
Frequent Visitor

Query Editor R Script table 'disappears' when script is run

I am experimenting with R script in power bi and am running into an odd issue. I have a column called 'Date' in my file which is a datetime variable 'Date' which power BI appears to be converting back to a string. In order to pull the hour from it I ran a simple line of code:
dataset$Hour=format(as.POSIXct(dataset$Date, format="%Y-%m-%d %H:%M:%S"), format="%H")

 

This code does not return any errors, however instead of returning the original table modified to include a new column, it returns an empty table with two columns, 'name' and 'value'. Furthere experimentations shows this empty table phenomenon seems to appear whenever I attempt to add or modify a column with R Script, possibly whenever I run any R script at all.

Would anyone know what could be the cause of this, and more importantly how to fix it?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

@jkraush1,

You can run the following R script to get hour.

 

 

# 'dataset' holds the input data for this script
dataset$StrDate<- as.character(dataset$Date)

x<-as.character(dataset$StrDate)

substrRight <- function(x, n){
  substr(x, nchar(x)-n+1, nchar(x))
}

dataset$time<-substrRight(x, 12)
dataset$hour<-substr(dataset$time,1,3)

output<-dataset

1.PNG

Regards,
Lydia

View solution in original post

1 REPLY 1
Anonymous
Not applicable

@jkraush1,

You can run the following R script to get hour.

 

 

# 'dataset' holds the input data for this script
dataset$StrDate<- as.character(dataset$Date)

x<-as.character(dataset$StrDate)

substrRight <- function(x, n){
  substr(x, nchar(x)-n+1, nchar(x))
}

dataset$time<-substrRight(x, 12)
dataset$hour<-substr(dataset$time,1,3)

output<-dataset

1.PNG

Regards,
Lydia

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.