🔹 Working with OneDrive as a Data Source in Power Apps – A Detailed Guide
📌 Introduction
OneDrive for Business is a cloud storage service that enables Power Apps to access, store, and manage files like Excel, images, PDFs, and more. By connecting OneDrive as a data source, you can:
✅ Store Excel files and use them as a database.
✅ Upload and retrieve images, PDFs, and documents.
✅ Use CSV or JSON files for data exchange.
✅ Integrate with Power Automate for automated workflows.
🔹 Step 1: Connecting OneDrive to Power Apps
To use OneDrive as a data source in Power Apps:
1️⃣ Open Power Apps Studio → Power Apps.
2️⃣ Click “Data” (Left Panel) → “Add Data”.
3️⃣ Search for OneDrive for Business and click “Add Connection”.
4️⃣ Sign in with your Microsoft 365 account.
5️⃣ Your OneDrive files are now accessible from Power Apps! 🎉
🔹 Step 2: Using Excel Files in OneDrive as a Data Source
Power Apps can use Excel files stored in OneDrive as a database.
A. Preparing an Excel File
Before using Excel in Power Apps:
✅ Format the data as a table → Select data → Click “Format as Table”.
✅ Ensure headers are present (e.g., Name, Email, Age).
✅ Save the file to OneDrive.
Example Excel Table (EmployeeData.xlsx)
| ID | Name | Age | |
|---|---|---|---|
| 1 | John | john@example.com | 30 |
| 2 | Sarah | sarah@example.com | 25 |
B. Connecting Excel File to Power Apps
- Click “Data” → “Add Data”.
- Select OneDrive for Business → Choose Excel file.
- Select the table name (e.g.,
EmployeeData). - Click “Connect” → Data is now available in Power Apps! ✅
C. Displaying Excel Data in a Gallery
- Insert a Gallery control (
Insert→Gallery→Vertical). - Set its Items Property to:
EmployeeData - Bind labels inside the gallery:
Title→ThisItem.NameSubtitle→ThisItem.Email
📌 Now, the Excel table data is displayed in Power Apps!
🔹 Step 3: Adding and Updating Data in Excel
Power Apps allows you to add new records or update existing ones in an Excel file stored in OneDrive.
A. Adding a New Record to Excel
- Insert Text Inputs (
txtName,txtEmail,txtAge). - Insert a Button (
Submit). - Set the OnSelect Property of the button:
Patch(EmployeeData, Defaults(EmployeeData), { Name: txtName.Text, Email: txtEmail.Text, Age: Value(txtAge.Text) } )
📌 Now, when the button is clicked, a new row is added to Excel! ✅
B. Updating an Existing Record
- Add a Gallery → Bind it to
EmployeeData. - Insert a Button (
Update). - Set the button’s OnSelect Property:
Patch(EmployeeData, LookUp(EmployeeData, ID = Gallery1.Selected.ID), { Name: txtName.Text, Email: txtEmail.Text, Age: Value(txtAge.Text) } )
📌 Now, selected data is updated in Excel!
🔹 Step 4: Deleting Data from Excel
To delete a record from an Excel table:
- Add a Trash Icon inside the Gallery.
- Set its OnSelect Property:
Remove(EmployeeData, ThisItem)
📌 Now, clicking the delete icon removes the row from Excel! ✅
🔹 Step 5: Uploading and Accessing Files in OneDrive
Power Apps can upload, retrieve, and view files like PDFs, images, and documents stored in OneDrive.
A. Uploading a File to OneDrive
To save an image or file from Power Apps:
- Insert a “Add Picture” control (
AddMediaButton1). - Insert a Button (
Upload). - Set the button’s OnSelect Property:
OneDriveForBusiness.CreateFile( "PowerApps Uploads/" & AddMediaButton1.FileName, AddMediaButton1.Media )
📌 Now, images are stored in OneDrive under PowerApps Uploads folder. ✅
B. Fetching and Displaying Files from OneDrive
To show images stored in OneDrive:
- Insert an Image Control.
- Set its Image Property:
OneDriveForBusiness.ListFiles("PowerApps Uploads/").value
📌 Now, images uploaded to OneDrive appear inside Power Apps!
🔹 Step 6: Automating OneDrive with Power Automate
You can use Power Automate to automate OneDrive workflows like file approvals, renaming, or moving files.
A. Example Power Automate Flow: Send Email on File Upload
- Trigger: “When a new file is created in OneDrive”.
- Action: “Send an email (Outlook)”.
- Body: “A new file has been uploaded:
FileName“. - Test & Save.
- Call the Flow from Power Apps:
FileUploadFlow.Run("PowerApps Uploads/" & AddMediaButton1.FileName)
📌 Now, users receive an email when a file is uploaded. ✅
🔹 Best Practices for Using OneDrive in Power Apps
✅ Use Excel Tables for Data → Always format Excel as a table.
✅ Limit Data Size → Excel isn’t ideal for large datasets (use Dataverse or SQL instead).
✅ Use Power Automate for File Handling → Automate file uploads and approvals.
✅ Optimize Performance → Avoid fetching entire datasets; filter instead.
✅ Secure Data Access → Set proper OneDrive permissions to prevent unauthorized access.
🔹 Conclusion
Using OneDrive as a data source in Power Apps allows you to store, retrieve, and manage files and data efficiently. You can integrate Excel as a database, upload images, fetch documents, and automate workflows using Power Automate.
💡 For better scalability, consider using SharePoint, Dataverse, or SQL Server instead of OneDrive for large datasets!
