【问题标题】:How to add column in Power BI by run R script in query editor如何通过在查询编辑器中运行 R 脚本在 Power BI 中添加列
【发布时间】:2019-07-10 02:18:05
【问题描述】:

1 - 输入表调用:"Table1"

Year   Profit
2019   300
2018   200
2017   100

2 - 在 Power Query 编辑器中的 “运行 R 脚本” 按钮中运行此脚本

# 'dataset' holds the input data for this script

dataset <- as.data.frame(Table1)
dataset["new"] <- NA

3 - 错误:

DataSource.Error: ADO.NET: R script error.
 as.data.frame(Table1) Error:  no object 'Table1'

解决这个错误的方法是什么?

【问题讨论】:

  • 我认为这是因为在 R 脚本中,Table1 被“存储”在变量 dataset 下,所以您可能想尝试dataset &lt;- as.data.frame(dataset)
  • 谢谢朱利安。它返回:我这个表是空的。我只需要一些简单的步骤来开始塑造数据,还有更直接的解决方案吗?

标签: r powerbi


【解决方案1】:

来自 csv 的输入数据:Table1

Year   Profit
2019   300
2018   200
2017   100

然后,通过从 Power BI Desktop 的“主页”选项卡中选择编辑查询打开查询编辑器

转换选项卡中,选择运行 R 脚本

# 'dataset' holds the input data for this script

output <- dataset
output$new <- NA

您需要将 R 脚本的输出命名为 output,这里是您的表格,其中包含新列 new

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多