cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thayward
Regular Visitor

PowerBI - run a query against a dataset to add new rows in an excel sheet

Hi there,

 

Currently, I pull data from a CRM system using an API. Because of this, we can't look at the 'state' of the system historically as it updates automatically.

My thinking is to create a DAX formula that summarises the data I need, then run this through a 'Run a query against a dataset' and then add the result from the DAX formula into a new row in an Excel spreadsheet.

 

I've got a DAX formula which uses 'SUMMARIZECOLUMNS' to gain the result I want, but I am having trouble putting this into an Excel spreadsheet as new rows.

 

Could anyone help me on this?

 

Thanks,

Tom

2 ACCEPTED SOLUTIONS

Accepted Solutions
thayward
Regular Visitor

@renearide I did find a solution but it's not the most ideal one.

thayward_0-1669021232784.png

This is the flow I am using. Essentially it runs the query, creates a CSV table of results, then that table of results is put into a new row in Excel. The problem with this is that it puts ALL the results into one cell, so you have to do transformations on the data afterwards to extract the data. The Excel my flow creates is pulled back into PowerBI anyway so I can use some Power Query functions to transform each cell into the actual table I desire.

I hope this helps.

View solution in original post

mmicsa
Frequent Visitor

Hi all

 

I was struggling with the same issue, and managed to finally solve it, so I'll leave my solution here.

A few introductory words about my use case first. 

I have a PowerApps application that stores data in a SharePoint list. I was looking for a way of automatically generating an Excel output based on that data, but with the added difficulty of having to also run 2 Power Queries where one result is used to filter the other result.

In the end, I added the 2 Power Queries to a Power BI and just did a basic table, just to be able to map the required data:

mmicsa_0-1708936650646.png

 

mmicsa_4-1708937778442.png

 

When this was done, well, basically I followed this video from Reza : How to Export Power BI Data to Excel | Query against a dataset (youtube.com)

Unfortunately, for what I needed, large export, not launched from the Dashboard, Reza and all others I could find, only exported to CSV, not Excel.
Still, it was a good starting point.

Now, here comes my twist to the solution, and a massive shoutout to a colleague from work who helped me with this issue. 

Instead of CSV table, we used the Parse JSON node as, well, the output of the "Run a query ... " is actually a JSON.

mmicsa_2-1708937182252.png

 

The "catch" here is that you have to generate your own Schema for this to work.

In order to generate the Schema, I used this webpage: Excel to JSON Converter: Convert Excel sheet to JSON table format (codebeautify.org)

But you can obviously use whatever solution you find.

Once that is done, it's just a matter of mapping you excel table rows to the output:

 

mmicsa_3-1708937539860.png

Now, as a last piece of advice, save yourself the pain, and check if values exist (hence all the if's).

It really doesn't like missing data.

As that was another pain point (ask me how I know), here's an example Expression of how to check if there is a value:

if(contains(item(), 'your item here'), item()['your item here'], '')
 
So, that's pretty much it and solves all my problems, no premium connectors, no conversions or anything, just built in functionality.
Hope this saves someone a few days of their lives (again, ask me how I know 😁)

View solution in original post

13 REPLIES 13

@thayward Did you find any solution? I also need to run a query and add rows in Excel.

thayward
Regular Visitor

@renearide I did find a solution but it's not the most ideal one.

thayward_0-1669021232784.png

This is the flow I am using. Essentially it runs the query, creates a CSV table of results, then that table of results is put into a new row in Excel. The problem with this is that it puts ALL the results into one cell, so you have to do transformations on the data afterwards to extract the data. The Excel my flow creates is pulled back into PowerBI anyway so I can use some Power Query functions to transform each cell into the actual table I desire.

I hope this helps.

If anyone is reading this old post, the solution I found was to run a ForEach loop of the data returned by PowerBI (Since it's an array), add the "Add a row into a table" step and then used this expression in any of your desired fields:

 

items('Apply_to_each')?['<Name of the query>[<Name of column>]']

 

So let's say you have a query called "Reports" and the column is called "Created Date", it would look like this

 

items('Apply_to_each')?['Reports[Created Date]']

 

And that would return only that specific value instead of the whole table.

Thank you Sir, may please share some screen capture for this method ? I tried but not easy to understand. many thanks!

I am trying to run a query against a dataset and output the result to an Excel. When it runs, it is for all the rows, but for all the rows, I am getting only NULL output and the Excel file has only blank rows (all column values are blank). I am not sure how to achieve it.

 

I used item()?['System Name']item()?['SLA Time'] for the column inputs and so on

 

Below is the output I am getting from "Run a query against a dataset" step

 

I am not sure where I am going wrong. Any help would be appreciated

[
  {
    "[System Name]": "System AAA",
    "[SLA Time]": "1899-12-30T08:00:00",
    "[Start Time for System]": "2023-06-16T07:35:00",
    "[End Time for System]": "2023-06-16T08:05:00",
    "[SLA Breach]": 1,
    "[Status for System]": "SUCCESS"
  },
  {
    "[System Name]": "System BBB",
    "[SLA Time]": "1899-12-30T08:00:00",
    "[Start Time for System]": "2023-06-16T06:30:00",
    "[End Time for System]": "2023-06-16T06:45:00",
    "[SLA Breach]": 0,
    "[Status for System]": "SUCCESS"
  },
  {
    "[System Name]": "System CCC",
    "[SLA Time]": "1899-12-30T07:00:00",
    "[Start Time for System]": "2023-06-16T06:30:00",
    "[SLA Breach]": 0,
    "[Status for System]": "IN-PROGRESS"
  }
]

 

Run a query against a Dataset.png

How can I reset the Excel file every time before I fill it?

mmicsa
Frequent Visitor

Hi all

 

I was struggling with the same issue, and managed to finally solve it, so I'll leave my solution here.

A few introductory words about my use case first. 

I have a PowerApps application that stores data in a SharePoint list. I was looking for a way of automatically generating an Excel output based on that data, but with the added difficulty of having to also run 2 Power Queries where one result is used to filter the other result.

In the end, I added the 2 Power Queries to a Power BI and just did a basic table, just to be able to map the required data:

mmicsa_0-1708936650646.png

 

mmicsa_4-1708937778442.png

 

When this was done, well, basically I followed this video from Reza : How to Export Power BI Data to Excel | Query against a dataset (youtube.com)

Unfortunately, for what I needed, large export, not launched from the Dashboard, Reza and all others I could find, only exported to CSV, not Excel.
Still, it was a good starting point.

Now, here comes my twist to the solution, and a massive shoutout to a colleague from work who helped me with this issue. 

Instead of CSV table, we used the Parse JSON node as, well, the output of the "Run a query ... " is actually a JSON.

mmicsa_2-1708937182252.png

 

The "catch" here is that you have to generate your own Schema for this to work.

In order to generate the Schema, I used this webpage: Excel to JSON Converter: Convert Excel sheet to JSON table format (codebeautify.org)

But you can obviously use whatever solution you find.

Once that is done, it's just a matter of mapping you excel table rows to the output:

 

mmicsa_3-1708937539860.png

Now, as a last piece of advice, save yourself the pain, and check if values exist (hence all the if's).

It really doesn't like missing data.

As that was another pain point (ask me how I know), here's an example Expression of how to check if there is a value:

if(contains(item(), 'your item here'), item()['your item here'], '')
 
So, that's pretty much it and solves all my problems, no premium connectors, no conversions or anything, just built in functionality.
Hope this saves someone a few days of their lives (again, ask me how I know 😁)

Wow thank you mmicsa!! That works absolutely brilliantly. I spent some time getting round the JSON schema but managed to get ChatGPT to write the schema by giving it the tabular format of what I wanted.

 

Very useful. Thank you for your help.

Where did that formula "items('Apply_to_each')?['Reports[Created Date]']" go, was that the formula you entered in the apply to each? Or did you put the outputs of PBI in the apply to each and that formula you mentioned was entered in the "Add a row into table"?

Hi @mmicsa ,

 

thank you for your post - I am trying to replicate this to my flow (to get nr. of emails from outlook and store it to Sharepoint list) however I am stuck with the "IF" functions.

 

Can you please share detail of this function? I do not have item as available field when writing expression and switching to dynamic content. I have only following to select:

jsarlii_1-1711464787026.png

 

The only way how to get item from Parse JSON is to create nested Apply to each steps but this is returning error in flow.

 

jsarlii_0-1711464213001.png

 

Thank you for any help!
Ivanuska

 

Hello

 

You're referencing the item incorrectly.

It's item(),what part of the item.

If you think of it like an array, (cause it kinda is), you're trying to tell it what "part" of the array you want.

 

                    if(contains(item(), 'your item here'), item()['your item here'], '')

Translation: if(not blank("array","identifier"), then Array()[Identifier], blank)

Item() - just references the current item, as we are in a loop.

To get the rest, take one of your failed runs and get the raw output and that will help you identify the correct names.

Hope this helps.

Hi @mmicsa ,

 

this is the output of Parse JSON action:

{
  "Mailboxes[Folder Path]": "\\Inbox\\Completed\\",
  "Mailboxes[Mailbox]": "mail@company.com",
  "[Nr. of Emails]": 10,
  "[Upload Date]": "2024-03-26T00:00:00"
}

 

Could you please point me to the right direction how to refer to the object within this array?

 

Thank you
Ivanuska

Should be something like:

 

If(contains(item(),'Mailboxes[Folder Path]', item()['Mailboxes[Folder Path]'],'')

Good luck.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (645)