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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

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
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.