Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowData Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more
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?
Solved! Go to Solution.
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
Regards,
Lydia
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
Regards,
Lydia
Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.
Check out the May 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 23 | |
| 21 | |
| 20 | |
| 17 | |
| 13 |
| User | Count |
|---|---|
| 58 | |
| 51 | |
| 37 | |
| 30 | |
| 26 |