Power BI 中的 R 脚本将日期返回为 Microsoft.OleDb.Date [英] R script in Power BI returns date as Microsoft.OleDb.Date

查看:17
本文介绍了Power BI 中的 R 脚本将日期返回为 Microsoft.OleDb.Date的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Powerbi会像这样显示2017-01-04 (yyyy-mm-dd)形式的数据?

Why does Powerbi show data of the form 2017-01-04 (yyyy-mm-dd) like this?

我正在尝试使用 Edit Query 中的 Run R Script 功能转换 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 with 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

使用 Get Data,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:

但是,当尝试使用相同数据运行 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)

如果我尝试更改数据类型,则会返回 en 错误:

If I try to change the data type, en error is returned:

这一切对我来说似乎很奇怪,而且我还没有使用谷歌找到合理的解释.

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:

以下是详细信息:

  1. 从 csv 文件加载数据后,转到 Edit Queries 并将数据类型更改为文本:
  1. After loading the data from the csv file, go to Edit Queries and change the data type to text:

  1. 运行 R 脚本

  1. Run the R script

脚本提供输出后,将数据类型改回 日期.

Change the datatype back to date once the script has provided an output.

这篇关于Power BI 中的 R 脚本将日期返回为 Microsoft.OleDb.Date的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆