pythonpython-3.xpowerbipowerbi-embeddedpower-bi-report-server

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'


Solution

  • 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