如何使用Python筛选Power BI服务仪表板?

huangapple go评论67阅读模式
英文:

How to filter a Power BI service dashboard using Python?

问题

I'm automating tasks in the Power BI service, and I've been able to create dashboards.

But now I need something else: Filter them, how can I do this?

df = (pd.read_excel(str('../00_config/users.xlsx'), sheet_name='users', converters={'user':str}))

with open('../03_ouput/users.csv', mode='w', newline='') as file_csv:
    write_csv = csv.writer(file_csv)
    write_csv.writerow(['user', 'link'])
file_csv.close()

i = 0

# Obtenemos tablero inicial.
get_dashboard = requests.get(endpoint, headers=headers)

if get_dashboard.status_code == 200:
    for cell_value in tqdm(column_users):
        new_dashboard_data = {
            "name": "Usuario - " + cell_value
        }
    
        clone_dashboard = requests.post(workspace_link_for_clone, json=new_dashboard_data, headers=headers)
        result_clone_dashboard = clone_dashboard.json()
        
        dashboard_link = result_clone_dashboard['webUrl']

        with open('../03_ouput/users.csv', mode='a', newline='') as file_csv:
            write_csv = csv.writer(file_csv)
            write_csv.writerow([cell_value, dashboard_link])
        file_csv.close()

        i+=1
else:
    print(get_dashboard.status_code)

That's my current code, what I did is run a loop to create boards in bulk, but now I also need to filter those boards with a different value each.

I tried to use powerbiclient, and I wrote this code statement (After having done the authentication)

report_edit = Report(group_id=group_id, report_id=report_id, auth=auth, view_mode=models.EmbedMode.EDIT.value, permissions=models.Permissions.READWRITE.value)

But I get this error:

module 'pyexpat.model' has no attribute 'EmbedMode'

英文:

I'm automating tasks in the Power BI service, and I've been able to create dashboards.

But now I need something else: Filter them, how can I do this?

df = (pd.read_excel(str('../00_config/users.xlsx'), sheet_name = 'users', converters={'user':str}))

with open('../03_ouput/users.csv', mode='w', newline='') as file_csv:
    write_csv = csv.writer(file_csv)
    write_csv.writerow(['user', 'link'])
file_csv.close()

i = 0

# Obtenemos tablero inicial.
get_dashboard = requests.get(endpoint, headers=headers)

if get_dashboard.status_code == 200:
    for cell_value in tqdm(column_users):
        new_dashboard_data = {
            "name": "Usuario - " + cell_value
        }
    
        clone_dashboard = requests.post(workspace_link_for_clone, json=new_dashboard_data, headers=headers)
        result_clone_dashboard = clone_dashboard.json()
        
        dashboard_link = result_clone_dashboard['webUrl']

        with open('../03_ouput/users.csv', mode='a', newline='') as file_csv:
            write_csv = csv.writer(file_csv)
            write_csv.writerow([cell_value, dashboard_link])
        file_csv.close()

        i+=1
else:
    print(get_dashboard.status_code)

That's my current code, what I did is run a loop to create boards in bulk, but now I also need to filter those boards with a different value each.

I tried to use powerbiclient, and I wrote this code statement (After having done the authentication)

report_edit = Report(group_id=group_id, report_id=report_id, auth=auth, view_mode=models.EmbedMode.EDIT.value, permissions=models.Permissions.READWRITE.value)

But I get this error:

> module 'pyexpat.model' has no attribute 'EmbedMode'

答案1

得分: 0

请确保您从正确的库中导入模型(from powerbiclient import models)。

如果您仍然遇到错误,可以尝试直接在view_model参数中提供数值(VIEW: 0, EDIT: 1, CREATE: 2)。

参考链接:

powerbi-jupyter / DOCUMENTATION

英文:

Please ensure that you are importing the models from the correct library (from powerbiclient import models).

if you are still facing the error, you can try directly providing the numerical values (VIEW: 0, EDIT: 1, CREATE: 2) in the view_model argument.

Reference:

powerbi-jupyter
/DOCUMENTATION

huangapple
  • 本文由 发表于 2023年5月22日 02:39:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76301398.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定