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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Import Excel to JSON o...
Power Automate
Unanswered

Import Excel to JSON or SQL Server

(0) ShareShare
ReportReport
Posted on by 4

Hi, I'm new to PowerAutomate and looking to import the following Excel table into our SQL Server database table or to JSON then into the database.

 

Here is the table

MichaelBailey1_0-1667829874814.png

I can get a row to import but nuisance here is that i/we need to add a column for each subsequent month with new values to import which would need to go in as addition rows, similar to the below but in SQL Server, so when the Dec-22 column is added to the above then there would be 12 additional rows like the below.

MichaelBailey1_1-1667830105259.png

 

Categories:
I have the same question (0)
  • v-dezhili-msft Profile Picture
    Microsoft Employee on at

    Hi @MichaelBailey1 ,

    Do you want to convert your data to json format?
    I have a test for your reference.
    vdezhilimsft_0-1667886391044.png
    vdezhilimsft_1-1667886391046.png
    vdezhilimsft_2-1667886391047.png
    vdezhilimsft_3-1667886391048.png
    vdezhilimsft_4-1667886391049.png

    Best Regards,

    Dezhi

  • MichaelBailey1 Profile Picture
    4 on at

    Hi Dezhi,

     

    I'm getting a valiudation error on the 'Append to array variable 3', can you confirm the formula... 

    variables('A') item()['Month'] item()['Value']
     
    Re: inserting as a JSON - Yes, happy to insert into the DB as a JSON value.
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    @MichaelBailey1 This is how I would build my flow. We can add as many Date columns as we want, and the flow will still produce the proper output.

     

    I have an Excel Table with the following data.

    grantjenkins_0-1668322226148.png

     

    Below is the full flow. I'll go into each of the actions.

    grantjenkins_1-1668322287121.png

     

    List rows present in a table returns all the Excel Table data.

    grantjenkins_2-1668322333342.png

     

    Before we move onto the next step, I just wanted to show you what output we get from this, especially the auto-generated columns. Below is the data for the first object.

    {
     "@odata.etag": "",
     "ItemInternalId": "0463dc90-b6b5-405b-be61-b07260a8afd0",
     "Category": "Cat 1",
     "Oct-22": "15",
     "Nov-222": "39",
     "Dec-22": "41"
    }

     

    Compose extracts out the data from the first object excluding the first three properties (the first two properties will be the auto-generated ones that Excel produces, and the third will be the Category - as shown in the object above). Effectively we want to get a list of all the Date Column Headers. The expression I use here is:

    skip(split(replace(string(first(outputs('List_rows_present_in_a_table')?['body/value'])), '"', ''), ','), 3)

     

    If we work from inside out, we can see that we get the first object, then convert it to a string, then replace the " with an empty string (effective removing the "), split by comma, and skip the first three properties.

    grantjenkins_3-1668322685258.png

     

    The result of this would be something like that below. You'll note that we still need to clean it up a bit to get just the dates.

    [
     "Oct-22:15",
     "Nov-222:39",
     "Dec-22:41}"
    ]

     

    Next, we use a Select using substring to get the Dates only. Each row will get all characters up to the colon :

    substring(item(), 0, indexOf(item(), ':'))

    grantjenkins_4-1668323431357.png

     

    The output would be:

    [
     "Oct-22",
     "Nov-222",
     "Dec-22"
    ]

     

    We then initialize an array variable called data that will eventually contain all the objects.

    grantjenkins_5-1668323520722.png

     

    Our Apply to each takes in the output from our Select so that we iterate over each of the Months.

    grantjenkins_7-1668323606941.png

     

    Our Select Month Data uses the value from List rows present in a table and builds up an object with the properties Category, Month, and Value.

    grantjenkins_8-1668323694546.png

     

    Category uses the Category field from List rows present in a table.

     

    Month uses the Current Item which is the expression below. Effectively, it gets the current Month we are looping over.

    items('Apply_to_each')

     

    Value comes from List rows present in a table but passes in the Month to dynamically get the appropriate property value. It uses the following expression:

    item()?[items('Apply_to_each')]

     

    This will give us an array of objects for the current Month we are iterating over.

     

    Next, we use another Compose to join this array with the array variable, so we end up with an array of objects from all months. The expression used here is:

    union(body('Select_Month_Data'), variables('data'))

    grantjenkins_9-1668324075914.png

     

    We then set the data array variable to the output of the union using Set variable data.

    grantjenkins_10-1668324095984.png

     

    We now have all the objects stored in the data array. The Compose after the Apply to each is just there to show the data in the array.

    grantjenkins_11-1668324157197.png

     

    The final output for the three Months is below:

    [
     {
     "Category": "Cat 1",
     "Month": "Dec-22",
     "Value": "41"
     },
     {
     "Category": "Cat 2",
     "Month": "Dec-22",
     "Value": "1"
     },
     {
     "Category": "Cat 3",
     "Month": "Dec-22",
     "Value": "1"
     },
     {
     "Category": "Cat 4",
     "Month": "Dec-22",
     "Value": "0"
     },
     {
     "Category": "Cat 5",
     "Month": "Dec-22",
     "Value": "25"
     },
     {
     "Category": "Cat 6",
     "Month": "Dec-22",
     "Value": "19"
     },
     {
     "Category": "Cat 7",
     "Month": "Dec-22",
     "Value": "18"
     },
     {
     "Category": "Cat 8",
     "Month": "Dec-22",
     "Value": "13"
     },
     {
     "Category": "Cat 9",
     "Month": "Dec-22",
     "Value": "33"
     },
     {
     "Category": "Cat 10",
     "Month": "Dec-22",
     "Value": "3"
     },
     {
     "Category": "Cat 11",
     "Month": "Dec-22",
     "Value": "39"
     },
     {
     "Category": "Cat 12",
     "Month": "Dec-22",
     "Value": "25"
     },
     {
     "Category": "Cat 1",
     "Month": "Nov-222",
     "Value": "39"
     },
     {
     "Category": "Cat 2",
     "Month": "Nov-222",
     "Value": "48"
     },
     {
     "Category": "Cat 3",
     "Month": "Nov-222",
     "Value": "5"
     },
     {
     "Category": "Cat 4",
     "Month": "Nov-222",
     "Value": "32"
     },
     {
     "Category": "Cat 5",
     "Month": "Nov-222",
     "Value": "42"
     },
     {
     "Category": "Cat 6",
     "Month": "Nov-222",
     "Value": "3"
     },
     {
     "Category": "Cat 7",
     "Month": "Nov-222",
     "Value": "20"
     },
     {
     "Category": "Cat 8",
     "Month": "Nov-222",
     "Value": "14"
     },
     {
     "Category": "Cat 9",
     "Month": "Nov-222",
     "Value": "14"
     },
     {
     "Category": "Cat 10",
     "Month": "Nov-222",
     "Value": "4"
     },
     {
     "Category": "Cat 11",
     "Month": "Nov-222",
     "Value": "18"
     },
     {
     "Category": "Cat 12",
     "Month": "Nov-222",
     "Value": "12"
     },
     {
     "Category": "Cat 1",
     "Month": "Oct-22",
     "Value": "15"
     },
     {
     "Category": "Cat 2",
     "Month": "Oct-22",
     "Value": "7"
     },
     {
     "Category": "Cat 3",
     "Month": "Oct-22",
     "Value": "59"
     },
     {
     "Category": "Cat 4",
     "Month": "Oct-22",
     "Value": "58"
     },
     {
     "Category": "Cat 5",
     "Month": "Oct-22",
     "Value": "15"
     },
     {
     "Category": "Cat 6",
     "Month": "Oct-22",
     "Value": "49"
     },
     {
     "Category": "Cat 7",
     "Month": "Oct-22",
     "Value": "48"
     },
     {
     "Category": "Cat 8",
     "Month": "Oct-22",
     "Value": "20"
     },
     {
     "Category": "Cat 9",
     "Month": "Oct-22",
     "Value": "6"
     },
     {
     "Category": "Cat 10",
     "Month": "Oct-22",
     "Value": "39"
     },
     {
     "Category": "Cat 11",
     "Month": "Oct-22",
     "Value": "20"
     },
     {
     "Category": "Cat 12",
     "Month": "Oct-22",
     "Value": "34"
     }
    ]

     

  • v-dezhili-msft Profile Picture
    Microsoft Employee on at

    Hi @MichaelBailey1 

    Could you please tell me what your formula looks like?

     

    thumbnail_image.png

    Best Regards,

    Dezhi

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard