英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论