Project

Automating Power BI Dashboard Updates from SharePoint Excel

This project aims to establish an automated process where Power BI dashboards are dynamically updated whenever the linked Excel files stored in SharePoint are modified.

Empty image or helper icon

Automating Power BI Dashboard Updates from SharePoint Excel

Description

Achieving seamless integration between Power BI and SharePoint requires setting up a dynamic connection and scheduling automatic refreshes. This project explores various methodologies and best practices involving data gateways, Power BI service configurations, and automation tools. By the end of the project, users will have a robust system where any updates made to the Excel files on SharePoint will reflect in the corresponding Power BI dashboards without manual intervention.

The original prompt:

I have a power bi dashboard that is connected to an excel file that is in sharepoint. how can I get power bi to automatically update when the excel file is changed? Thanks

Introduction to Power BI and SharePoint Integration

In this guide, we will cover how to integrate Power BI with SharePoint to create dashboards that are dynamically updated when the linked Excel files stored in SharePoint are modified.

Setting Up the Environment

Prerequisites

  1. Office 365 Subscription: Ensure you have an active Office 365 subscription with access to Power BI Pro and SharePoint Online.
  2. Power BI Desktop: Download and install Power BI Desktop from the official Power BI website.

Getting the SharePoint Site URL

To integrate an Excel file from SharePoint into Power BI, you need the accurate URL of the SharePoint site and the location of the Excel file.

  1. Navigate to your SharePoint site where your Excel file is stored.
  2. Go to the document library where the Excel file is stored.
  3. Click on the Excel file to open it.
  4. Copy the URL from the browser address bar.

Steps to Connect Power BI to Your SharePoint Excel File

Step 1: Open Power BI Desktop

  1. Launch Power BI Desktop.
  2. Under the Home tab, click on Get Data.

Step 2: Choosing the Data Source

  1. In the Get Data window, search for SharePoint Folder.
  2. Click Connect.

Step 3: Entering the SharePoint URL

  1. In the SharePoint folder dialog, paste the URL of your SharePoint site (obtained earlier). You only need the site URL, not the entire path to the file.
    Example: https://yourcompany.sharepoint.com/sites/YourSiteName 
  2. Click OK.

Step 4: Authentication

  1. Authenticate using your organization credentials. This might involve using Microsoft’s Multi-Factor Authentication (MFA).

Step 5: Navigating and Selecting Your Excel File

  1. Once connected, Power BI will list all files and folders from your SharePoint.
  2. Find your Excel file in the list.
  3. Select the file and click on Transform Data.

Step 6: Transforming Data in Power Query Editor

  1. The Power Query Editor will open, showing the contents of your Excel file.
  2. Perform any necessary transformations or cleaning on your data.
    • Removing unwanted columns
    • Filtering rows
    • Renaming columns, etc.
  3. Once the transformations are done, click Close & Load to import the data into Power BI.

Creating and Publishing Your Dashboard

Step 1: Building the Report

  1. Use the imported data to create various visualizations in Power BI.
  2. Build and design your dashboard according to your needs.

Step 2: Publishing to Power BI Service

  1. Once your report is ready, click on Publish in the Home tab.
  2. Choose or create a workspace in the Power BI Service, and click Select.

Step 3: Setting Up Automatic Refresh

  1. Go to Power BI Service (https://app.powerbi.com).
  2. Navigate to the workspace where you published your report.
  3. Click on the dataset linked to your report.
  4. Go to Settings.
  5. Under the Data source credentials, add your authentication details if not added.
  6. Under Scheduled refresh, set up the refresh frequency (e.g., daily, hourly).
  7. Save and apply the changes.

Conclusion

By following the above steps, your Power BI dashboard will now dynamically update whenever the linked Excel files stored in SharePoint are modified. This setup ensures that your reports and insights are always based on the most current data available.

This concludes the practical implementation of integrating Power BI with SharePoint and setting up an automated data refresh process.

Setting Up the Data Gateway

To set up the data gateway for automatically updating Power BI dashboards whenever the linked Excel files in SharePoint are modified, follow these practical steps:

1. Install and Configure the On-premises Data Gateway

On-premises Data Gateway Installation

  1. Select the type of gateway: Use the On-premises data gateway (personal mode).
  2. Connect to your account: Sign in with your organizational account.

2. Configure the Gateway for Power BI

Data Source Configuration

  1. Data Source Name: Enter a meaningful name.
  2. Data Source Type: Select SharePoint.
  3. Authentication Method: Choose Windows for enterprise environments, otherwise use OAuth2.
  4. Credentials: Provide corresponding credentials for SharePoint access. Ensure it has access to the Excel files in SharePoint.

3. Connect the SharePoint Site and Excel Files in Power BI Desktop

  • Open Power BI Desktop.
  • Go to Get Data > More....
  • Select Online Services, then choose SharePoint Folder.

Connecting to SharePoint in Power BI Desktop

  1. Enter the SharePoint site URL.
  2. Click 'Connect'.
  3. In Navigator pane, locate the Excel files you wish to connect to.
  4. Load the file: Click 'Load' to import data into Power BI.
  5. Perform necessary transformations in Power Query.

4. Publish and Schedule Refresh

  • After designing your reports in Power BI Desktop, publish the report to Power BI Service.

Publishing and Scheduling

  1. Click 'Publish' on the Home ribbon in Power BI Desktop.
  2. Select the destination workspace.
  3. After publishing, go to Power BI Service and set up the scheduled refresh:
    • Navigate to Datasets, select your dataset.
    • Go to Scheduled refresh.
    • Enable Scheduled refresh.
    • Set the appropriate refresh schedule according to your needs.

5. Automate the Refresh Based on SharePoint File Changes

  • This involves advanced scripting in Power Automate (formerly Microsoft Flow) to trigger the refresh when files are modified.

Power Automate Flow Configuration

  1. Create a new flow:
    • Trigger: When a file is modified (properties only) in SharePoint.
    • Action: Refresh a dataset in Power BI.

Example Flow Steps

  1. Trigger: SharePoint
    • Site Address: Enter the SharePoint site address.
    • Library Name: Enter the document library name.
  2. Action: Power BI
    • Workspace: Select the workspace.
    • Dataset: Select the dataset you wish to refresh.

Power Automate Example Pseudocode Flow

TRIGGER: When file is modified IF File.Path == "YourExcelFilePath" THEN ACTION: Refresh dataset parameters: WorkspaceName = "YourWorkspaceName" DatasetName = "YourDatasetName"

By following these steps, you'll have implemented an automated data refresh system that updates your Power BI dashboards dynamically based on changes in your SharePoint-stored Excel files.

Configuring Automatic Refresh Schedules

Overview

To set up automatic refresh schedules for Power BI dashboards so they update whenever linked Excel files stored in SharePoint are modified, follow the steps below. This will involve using Power BI Service for scheduling the refresh and ensuring data gateway configurations are already in place.

Steps

  1. Open Power BI Service:

  2. Locate Your Dataset:

    • In the left navigation pane, click on "Workspaces" and then select the workspace containing your dataset.
    • Click on "Datasets + dataflows".
  3. Configure Refresh Settings:

    • Find your dataset connected to your SharePoint Excel file.
    • Click on the ellipse (...) next to your dataset, and select "Schedule Refresh".
  4. Set Up Scheduled Refresh:

    • Under the "Scheduled refresh" section:
      • Turn the "Keep your data up to date" toggle switch to On.
      • Set the Refresh frequency to either "Daily" or "Weekly" as per your requirement.
      • Specify the time of day and days of the week for the refresh.
  5. Gateway Connection (if applicable):

    • Ensure your gateway connection is properly configured under the "Data source credentials" section.
    • If you’re using a data gateway, make sure the connection is properly mapped.
  6. Save Your Settings:

    • Click on the "Apply" button to save your refresh settings.

Example: JSON-based Configuration

If you're using Power BI REST API for advanced automation or managing refresh schedules programmatically, below is an example how you might set the refresh schedule using Power BI REST API.

POST https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/refreshSchedule
Content-Type: application/json

{
  "value": [
    {
      "days": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
      "times": ["08:00", "12:00", "17:00"],
      "enabled": true
    }
  ]
}

In the JSON example above:

  • days specifies the days of the week for refreshes.
  • times specifies the times of the day for each refresh.
  • enabled sets the schedule to active.

Conclusion

Follow these steps to ensure your Power BI dashboard dynamically updates whenever your linked Excel files in SharePoint are modified. Adjust the schedules to reflect the granularity and frequency as required by your business needs. The REST API configuration can be used for more advanced or automated scheduling requirements.

Incremental Data Updates for Power BI Dashboards with SharePoint Integration

To implement incremental data updates for Power BI dashboards linked with Excel files stored in SharePoint, follow the steps below. The solution presumes that you have already set up Power BI and integrated it with SharePoint, configured necessary data gateways, and set up automatic refresh schedules.

Requirements:

  • Power BI Service
  • SharePoint Online
  • Power BI Gateway (if applicable for on-premises data sources)
  • Basic understanding of Power Query and Power BI

Step-by-Step Implementation

1. Ensure Version History is Enabled in SharePoint

Ensure that versioning is enabled for your SharePoint document library where the Excel files are stored. This ensures that changes can be tracked and only the updates are fetched by Power BI.

2. Load Data with Power Query

Load your initial dataset in Power BI using Power Query. Follow these steps to tailor Power Query for incremental updates.

// Example: Load Data from SharePoint
let
    Source = SharePoint.Files("https://yoursharepointsite/", [ApiVersion = 15]),
    ExcelFile = Source{[Name="yourfile.xlsx"]}[Content],
    Sheet = Excel.Workbook(ExcelFile),
    Data = Sheet{[Item="Sheet1",Kind="Sheet"]}[Data]
in
    Data

3. Implement Incremental Refresh in Power BI with Parameters

Incremental refresh can be implemented using parameters in Power BI, which filters the data loaded based on certain time constraints.

  1. Create Parameters:
    • RangeStart datetime
    • RangeEnd datetime
let
    Source = SharePoint.Files("https://yoursharepointsite/", [ApiVersion = 15]),
    ExcelFile = Source{[Name="yourfile.xlsx"]}[Content],
    Sheet = Excel.Workbook(ExcelFile),
    Data = Sheet{[Item="Sheet1",Kind="Sheet"]}[Data],
    FilteredData = Table.SelectRows(Data, each [Modified] >= RangeStart and [Modified] < RangeEnd) // Assuming 'Modified' column exists and is DateTime
in
    FilteredData
  1. Publish to Power BI Service:
    • After setting up the Power Query as above, publish your Power BI report to Power BI Service.

4. Configure Incremental Refresh Policy in Power BI Service

  1. In the Power BI Desktop, go to the incremental refresh policy configuration.
  2. Set the parameters for data refresh as needed (e.g., store data for the last 3 months, refresh data from the last 1 day).
// Example: Setting Incremental Refresh
Model
    .Tables["YourTable"]
    .Partitions["IncrementalRange"]
    .RangeStart = DateTime.LocalNow() - #duration(30, 0, 0, 0), // Last 30 days
    .RangeEnd = DateTime.LocalNow()

5. Set Up a Trigger in Power Automate

To ensure that your Power BI dataset is updated when changes are made to SharePoint files, create a Power Automate workflow.

  1. Create a Flow:
    • Trigger: "When a file is created or modified" (SharePoint)
    • Action: "Refresh a dataset" (Power BI)
// Example Flow Steps
1. Trigger: When a file is created or modified in a folder
    - Site Address: `https://yoursharepointsite`
    - Library Name: `Documents`
2. Action: Refresh a dataset
    - Workspace: `Your Power BI workspace`
    - Dataset: `Your Dataset Name`

Wrap-up

By following the above steps, you will set up an automated process where your Power BI dashboards are dynamically updated with incremental data changes from Excel files stored in SharePoint. This minimizes data transfer and processing time, making your reports more efficient and timely. Keep an eye on the dataset refresh logs in Power BI Service for monitoring and troubleshooting.

Monitoring and Troubleshooting the Automation Process

In the context of automatically updating Power BI dashboards from Excel files stored in SharePoint, monitoring and troubleshooting the process involves implementing checks to ensure data updates as expected and steps to resolve issues efficiently.

Monitoring the Automation Process

Logging and Notifications

Ensure you have a mechanism to log key steps and notify relevant stakeholders when updates occur, or issues are detected.

Pseudocode Implementation:

FUNCTION monitor_and_log_update()
    TRY
        log_event('Starting data refresh...')
        PERFORM data_refresh_action()
        log_event('Data refresh successful.')
        SEND_notification('Data refresh completed successfully')
    EXCEPT (Exception e)
        log_event('Data refresh failed: ' + e.message)
        SEND_notification('Data refresh failed: ' + e.message)
END FUNCTION

Sample Logging Function

Implement a basic logging system.

FUNCTION log_event(message)
    current_time = GET_CURRENT_TIME()
    LOG_TO_FILE(current_time + ': ' + message)
END FUNCTION

Sample Notification Function

You can use email or other messaging services for notifications.

FUNCTION send_notification(message)
    SEND_EMAIL('admin@example.com', 'Data Refresh Status', message)
END FUNCTION

Troubleshooting the Automation Process

Common Issues and Resolutions

  1. Data Gateway Connectivity Issues:

    • Check if the gateway service is running.
    • Validate credentials and network configurations.
    FUNCTION check_gateway_status()
        IF NOT IS_GATEWAY_RUNNING()
            LOG_AND_NOTIFY('Gateway is not running.')
            RESTART_GATEWAY_SERVICE()
            LOG_AND_NOTIFY('Gateway restarted.')
        END IF
    END FUNCTION
  2. Data Source Authentication Failures:

    • Re-authenticate data sources in Power BI Service.
    • Check for changes in SharePoint permissions.
    FUNCTION validate_data_source_access()
        TRY
            ACCESS_DATA_SOURCE()
        EXCEPT (AuthenticationError e)
            LOG_AND_NOTIFY('Data source authentication failed: ' + e.message)
            PROMPT_USER_FOR_CREDENTIALS()
            REAUTHENTICATE_DATA_SOURCE()
        END TRY
    END FUNCTION
  3. Scheduling Errors:

    • Ensure that refresh schedules are correctly configured in the Power BI Service.
    • Check logs for failed schedule triggers.
    FUNCTION verify_schedule_integrity()
        scheduled_tasks = GET_SCHEDULED_TASKS()
        FOR task IN scheduled_tasks
            IF task.last_run_status = 'FAILED'
                LOG_AND_NOTIFY('Scheduled task failed: ' + task.name)
                RESCHEDULE_TASK(task)
            END IF
        END FOR
    END FUNCTION

User Interaction for Re-Authentication

Prompt users to update their credentials when an authentication error occurs.

FUNCTION prompt_user_for_credentials()
    DISPLAY_MESSAGE('Please re-enter your credentials for the data source.')
    username = GET_USER_INPUT('Username:')
    password = GET_USER_INPUT('Password:', hidden=True)
    RETURN { 'username': username, 'password': password }
END FUNCTION

FUNCTION reauthenticate_data_source()
    credentials = PROMPT_USER_FOR_CREDENTIALS()
    SET_DATA_SOURCE_CREDENTIALS(credentials.username, credentials.password)
END FUNCTION

Summary

The provided implementation focuses on monitoring the process through logging and notifications and presents troubleshooting steps for common issues encountered during automation. When implemented correctly, this will ensure that the Power BI dashboards are reliably updated, and issues can be quickly identified and resolved.