web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Exporting gallery data...
Power Apps
Suggested Answer

Exporting gallery data to Excel or CSV with variable JSON showing blank

(2) ShareShare
ReportReport
Posted on by 475
Hello All,
 
I'm trying to export my gallery data to an Excel or CSV. I'm trying to follow Matthew Devaney's article Power Apps Export To Excel As A CSV File. When try to set my OnSelect for the button my var is showing Blank. My data is connected to a SharePoint list.
 
 
I'm not sure what's going on I don't have any errors. Any ideas would be greatly appreciated.
Categories:
  • Suggested answer
    Trait007 Profile Picture
    310 on at
    *** Chat GPT response to question ***
    Hi,

    To troubleshoot why your variable (var) is blank when trying to export gallery data to an Excel or CSV file, let's ensure all steps are correctly followed. Matthew Devaney's method is robust but requires precise setup.

    Key Steps to Follow:

    1. Ensure the Gallery Data Source is Valid
      Ensure your gallery (Gallery1) is correctly bound to the SharePoint list and is displaying the desired data.

      • Test the data source by previewing the app and confirming that the gallery is populated.
    2. Set the OnSelect Property of the Button
      Update the button's OnSelect property with the correct logic to create the CSV file.

      Example formula:

      ClearCollect(
      colExportData,
      ForAll(
      Gallery1.AllItems,
      {
      Column1: ThisRecord.Title,
      Column2: ThisRecord.Description,
      Column3: Text(ThisRecord.Created, "[$-en-US]yyyy-mm-dd")
      }
      )
      );
      Set(
      varCSVData,
      Concat(
      colExportData,
      Column1 & "," & Column2 & "," & Column3 & Char(10)
      )
      );
      Download(varCSVData, "GalleryData.csv", "text/csv")
      • Replace Column1, Column2, etc., with your actual column names.
      • Ensure the gallery's data structure matches the column names referenced in the formula.
    3. Check varCSVData Variable
      After setting varCSVData in the OnSelect formula, verify its content:

      • Add a Label to the screen with the Text property set to varCSVData.
      • Run the app and click the button to check if the variable is populated.
    4. Validate colExportData Collection
      If varCSVData is blank, the issue might be with the colExportData collection:

      • Temporarily add a Data Table to the screen.
      • Set its Items property to colExportData to confirm if the collection is being populated.
    5. Debug Common Issues

      • Empty Gallery: Ensure the gallery isn't empty, as this would result in a blank varCSVData.
      • Column Mismatch: Verify the column names used in the formula (ThisRecord.ColumnName) match those in your SharePoint list.
      • Data Formatting: If some fields are complex (e.g., Person or Choice fields), extract the value using .Value or .DisplayName.
    6. Test the Download Function
      After confirming varCSVData contains valid data, ensure the Download function works:

      • Test the Download function with a simple string, e.g., Download("Test,Data", "Test.csv", "text/csv").
    7. Browser Settings
      Ensure your browser allows file downloads. Some browsers block downloads in apps due to security settings.

    Additional Notes:

    • For a SharePoint Data Source: SharePoint lists often have fields like "Modified By" or "Person" which are objects. Access their values as ThisRecord.ColumnName.Value or ThisRecord.ColumnName.Email.
    • File Format: CSV files are suitable for smaller datasets. For larger datasets, consider integrating Power Automate to generate an Excel file.
    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!
  • nleuck_101 Profile Picture
    475 on at
    I'm getting an error on the Download.

  • timl Profile Picture
    37,418 Super User 2026 Season 2 on at
    Hi nleuck_101 
     
    Can you clarify how you're creating varJSONMail? In theory, something like this should work.
     
    Set(
         varJSONMail,
         JSON(
             ShowColumns(
                 YourGallery.AllItems,
                 "OutputColumn1",
                 "OutputColumn2",
                 "OutputColumn3"
             ),
             JSONFormat.IndentFour
         )
     )
     
    Note that the ChatGPT/AI generated answer in the post beneath won't work because there isn't a step that creates the GalleryData.csv that's specified there. You'll need to utilise the JSON/Flow method that you cited in Matthew Devaney's article. 
  • nleuck_101 Profile Picture
    475 on at
    Thanks timl
     
    Not sure what was wrong but it's fixed. I now have an error with a BadGateway. Now have to try and figure that out. 😅
  • timl Profile Picture
    37,418 Super User 2026 Season 2 on at
    Thanks for the update nleuck_101.
     
    Let us know if you need any more help on this. 
  • nleuck_101 Profile Picture
    475 on at
    I have a new error. The flow works and it creates the CSV file but it doesn't download the file like Matthew's example. What am I missing here?

  • timl Profile Picture
    37,418 Super User 2026 Season 2 on at
    Hi nleuck_101
     
    After you receive this error, can you go to the variables part of the designer and verify that the value of varCSVFile is set correctly to URL of the file?
     
    If not, I would investigate the part of the flow where you set linkoutput, and the Set statement where you retrieve this value.
  • nleuck_101 Profile Picture
    475 on at
    Are you talking about this?

  • timl Profile Picture
    37,418 Super User 2026 Season 2 on at
    Hi nleuck_101 
     
    What I mean is this part of the Power Apps designer. 
     
    Under Global variables, you should hopefully be able to view the value of the varCSVFile variable. If it's not a valid URL, that would help explain the error that you're seeing.
     
  • nleuck_101 Profile Picture
    475 on at
    Here is what I have. Pretty sure I followed Matthew's article correctly.
     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 236 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 188 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 130

Last 30 days Overall leaderboard