Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Script works online but not in Power Automate

I have a script it works online but when I add it to a power automate flow it is pulling in wrong data.  I basically have an employee file with status.  I want to filter off our various termed employees onto a separate sheet.  Once it is ran through Power Automate essentially every employee is moved to the term list.  We have roughly 10,000 employees and only a dozen or so people remain on the report.  Any suggestions.

 

function main(workbook: ExcelScript.Workbook) {

  const table = workbook.getTable("Table1");

  const EmployeeStatusColumn = table.getColumnByName("Employee Status");

  EmployeeStatusColumn.getFilter().applyValuesFilter(["Terminated","Backout","Fall off","Terminated w/Severance"]);

  workbook.addWorksheet().getRange().copyFrom(table.getRange());

  let sh: ExcelScript.Worksheet = workbook.getWorksheet("Report")

  let visibleRows = table.getRangeBetweenHeaderAndTotal().getVisibleView().getRows()

  let firstVisibleRow = visibleRows[0].getRange().getRowIndex() + 1

  let lastVisibleRow = visibleRows[visibleRows.length - 1].getRange().getRowIndex() + 1

  sh.getRange(`${firstVisibleRow}:${lastVisibleRow}`).delete(ExcelScript.DeleteShiftDirection.up)

    table.getColumnByName("Employee Status")

    .getFilter()

    .clear();

}

1 REPLY 1
v-yalanwu-msft
Community Support
Community Support

Hi, @Syndicate_Admin ;

From your code found that there are filters, perhaps because the filter caused the data from 10,000 to a dozen employees, you try to remove the filter to check if this is the reason, if so, change the filter.

Run Office Scripts with Power Automate - Office Scripts | Microsoft Learn


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors