Import Data from Excel to Dataverse using PowerApps

Leave a Comment

 Hi All , 

In this post , I would like to explain how Import the data from Excel to DataVerse(in my case) using Power Apps. 

I have defined one Excel file along with few columns and stored that excel file in sharepoint document library.Firstly I am fetching the values from Excel and passing this to PowerApps as an Output

Power Automate :

Please find the below Power Automate steps at high level ,










Add List rows Present in table connection and get the values from the Excel 








Now mapping the Excel columns











Respond sending back to Power Apps.




Power Apps :

I have created a button in Power Apps and added below code under OnSelect Property of the button.


UpdateContext({RegistrationData: ImportData_Excel_Restore.Run().registrationdetails});

ClearCollect(

    collRegistrationData,

    AddColumns(

        Split(

            ImportData_Excel_Restore.Run().registrationdetails,

            "|"

        ),

        "FirstName",

        Mid(

            Result,

            Find(

                "a/",

                Result

            ) + 4 + 1,

            Find(

                "b/",

                Result

            ) - (Find(

                "a/",

                Result

            ) + 4 + 2+2)

        ),

        "MiddleName",

        Mid(

            Result,

            Find(

                "b/",

                Result

            ) + 4 + 1,

            Find(

                "c/",

                Result

            ) - (Find(

                "b/",

                Result

            ) + 4 + 2+2)

        ),

        "LastName",

        Mid(

            Result,

            Find(

                "c/",

                Result

            ) + 4 + 1,

            Find(

                "d/",

                Result

            ) - (Find(

                "c/",

                Result

            ) + 4 + 2+2)

        ),

        "DOB",

     DateValue(   Mid(

            Result,

            Find(

                "d/",

                Result

            ) + 4 + 1,

            Find(

                "}",

                Result

            ) - (Find(

                "d/",

                Result

            ) + 4+2)

        ))

    )

);

The above code will generate the collection from the Output we received from the Power Automate.


Updating the Data verse table :

I have added another button , which will use the above generated collection and patch the records to Dataverse table


ForAll(

    collRegistrationData,

    If(

        Not(

            Or(

                IsBlank(DOB),

                IsEmpty(DOB)

            )

        ),

        Patch(

            Registrations,

            Defaults(Registrations),

            {

                'First Name': FirstName,

                'Middle Name': MiddleName,

                'Last Name': LastName,

                'Date of Birth': Date(

                    Year(DateValue(Text(DOB))),

                    Month(DateValue(Text(DOB))),

                    Day(DateValue(Text(DOB)))

                ),

                IsImportedFromExcel: true

            }

        )

    )

);

Refresh(Registrations);

ClearCollect(

    collErrorRegistration,

    Errors(Registrations)

);

Thanks for reading 

Related Post

0 comments:

Post a Comment