Power BI中的R脚本将日期返回为Microsoft.OleDb.Date [英] R script in Power BI returns date as Microsoft.OleDb.Date
问题描述
我正在尝试使用编辑查询
中的运行R脚本
功能在Power BI中转换表。
表格的来源是一个csv文件,其日期列格式为 2017-01-04 (yyyy-mm-dd):
I'm trying to transform a table in Power BI using the Run R Script
functionality in Edit Query
.
The source of the table is a csv file with a column of dates of the format 2017-01-04 (yyyy-mm-dd):
2017-01-04
2017-01-03
2017-01-02
2017-01-01
2016-12-31
2016-12-30
2016-12-29
2016-12-28
2016-12-27
2016-12-26
2016-12-25
2016-12-24
2016-12-23
2016-12-22
使用获取数据
,Power BI显示相同的日期列,如下所示:
Using Get Data
, Power BI shows the same date column like this:
并打开编辑查询窗口
,相同的日期列仍然看起来像这样:
And after opening the Edit Query window
, the very same date column still looks like this:
但是,当尝试运行a n R条纹具有相同的数据,该列仅包含值 Microsoft.OleDb.Date
,例如:
However, when trying to run an R sctript with the same data, the column only consists of the "values" Microsoft.OleDb.Date
like this:
我正在运行的R脚本很简单:
The R script I'm running is simply:
# 'dataset' holds the input data for this script
output <- head(dataset)
如果我尝试更改数据类型,则会返回错误:
If I try to change the data type, en error is returned:
这一切对我来说都很奇怪,我还没有找到使用Google的合理解释。
It all seems very strange to me, and I haven't found a reasonable explanation using Google.
有什么建议吗?
推荐答案
我已经在评论中提供了解决方案,但是我将添加一个这里的详细建议
I already provided a solution in the comments, but I'll add a detailed suggestion here as well.
在Power BI中应用的步骤和结果日期列应如下所示:
The applied steps in Power BI and the resulting date column should look like this:
以下是详细信息:
- 从csv文件加载数据后,转到编辑查询并将数据类型更改为文本:
- After loading the data from the csv file, go to Edit Queries and change the data type to text:
-
运行R脚本
Run the R script
在脚本提供输出后,将数据类型改回日期。
Change the datatype back to date once the script has provided an output.
这篇关于Power BI中的R脚本将日期返回为Microsoft.OleDb.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!