This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreGet Fabric Certified for FREE during AI Skills Fest. This week only. Secure your voucher now.
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
Check out the May 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 25 | |
| 24 | |
| 22 | |
| 21 | |
| 19 |
| User | Count |
|---|---|
| 51 | |
| 48 | |
| 44 | |
| 21 | |
| 21 |