Power BI 参数是否暴露给 Python 全局变量
问题描述
我正在使用 Python 脚本处理 Power BI 请求.我可以通过 dataset
全局变量获取数据集,但现在我希望能够直接在我的 Python 脚本中获取传递的参数.
I'm working on Power BI requests with Python scripting.
I'm able to get the dataset through dataset
global variable, but now I'd like to be able to get the passed parameters directly in my Python script.
我尝试打印"(我们不能真正直接在 PowerBI 中打印,所以我使用 raise Exception(WhatIWantToDebug)
以便直接在 PowerBI 中查看我的错误)globals()
,它显示了在 Python 脚本的上下文中声明可访问的所有全局变量,但我无法找到任何有关参数的内容.不过我可以看到数据集.
I tried to "print" (we cannot really print directly in PowerBI so I use raise Exception(WhatIWantToDebug)
in order to see my error directly in PowerBI) the globals()
, which show all the globals variables declared accessible in the context of the Python script, but I'm not able to find anything concerning parameters. I'm able to see dataset though.
提前感谢您的解决方案想法
Thanks in advance for your solutions ideas
解决方案
我终于找到了解决问题的方法.所以没弄清楚如何在Python中直接获取参数.
I've finally find a solution to my problem. So I didn't figure out how to get parameters directly in Python.
但我不是创建参数,而是说参数 A
、B
、C
.为了在 Python 中使用它,我使用源创建了一个请求:
But instead of that I create parameters, let's say parameters A
, B
, C
.
To use it in Python, I create a request with the source :
= Table.FromColumns({{A}, {B}, {C}}, {"parameterA", "parameterB", "parameterC"})
之后,我的参数可以通过 pandas
After that, my parameters are accessible in the dataset dict with pandas
parameterA = dataset['parameterA'][0])
parameterB = dataset['parameterB'][0])
parameterC = dataset['parameterC'][0])
希望对你有帮助
相关文章