
Announcements
Hi everyone,
I have a flow that extracts informtion: 'Transaction Date' and 'Amount' from images and adds extracted data into excel.
Can I somehow adjust my flow so it sorts the data by Date asc?
This is how the excel sheet looks
This is a step which adds rows:
For 'Amount' I have a function to replace commas with dots to make =sum() work.
Maybe I can put 'Transaction date' into some kind of 'sort by' function so it sorts data?
Hi @AusarZ ,
It looks like the easiest solution here is to create an Office Script to perform this action. The Office Scripts allows you to automate tasks inside Excel for Web, performing a similar role of VBA in Excel Desktop (but written in TypeScript). Also, the Office Scripts can be ran from Power Automate 🙂
I ran a quick test with the following table:
Than I used the following Office Script:
And this was the result:
To create an Office Script, you just need to go to "Automation" tab in your Excel, and click in "New Script". Then a Code editor will appear in the right side of the screen, where you can insert your script:
To run it from Power Automate, you just use the "Run Script" action, and select the file and the script that you want to run:
Here is the full code:
function main(workbook: ExcelScript.Workbook) {
const table = workbook.getTable('Table1') //returns the table
table.getSort().apply([{key: 0, ascending: true}]) //sorts the table based in its firt column, in asc
}
From your end, make sure to change your table name in the following line: const table = workbook.getTable([table name here, between quotes]). You can also change the index of the column that you want to use to sort the table, by changing the key property from
Finally, I wrote some blog posts about this topic, and I'm sharing it here in case of you or any other user wants to learn more about Office Scripts:
- Office Scripts, the new VBA: http://digitalmill.net/2023/06/10/office-scripts-the-new-vba/
- Getting started with Office Scripts: http://digitalmill.net/2023/06/19/get-started-with-office-scripts/
- Accessing Excel ranges with Power Automate: http://digitalmill.net/2023/09/01/accessing-excel-ranges-with-power-automate/
Let me know if it works for you or if you need any additional help!
-------------------------------------------------------------------------
If this is the answer for your question, please mark the post as Solved.
If this answer helps you in any way, please give it a like.
http://digitalmill.net/
https://www.linkedin.com/in/raphael-haus-zaneti/