• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Office Script - Power Automate / Data Type Issues with setNumberFormat|General Excel Questions & Answers|Excel Forum|My Online Training Hub

You are here: Home / Office Script - Power Automate / Data Type Issues with setNumberFormat|General Excel Questions & Answers|Excel Forum|My Online Training Hub

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumGeneral Excel Questions & Answe…Office Script - Power Automate / Da…
sp_PrintTopic sp_TopicIcon
Office Script - Power Automate / Data Type Issues with setNumberFormat
Avatar
Peter Fresh
Member
Members
Level 0
Forum Posts: 13
Member Since:
August 6, 2020
sp_UserOfflineSmall Offline
1
December 22, 2022 - 8:17 pm
sp_Permalink sp_Print

Hi @all,

I am currently working on a project where I need to run an office script through Power Automate.

In the associated excel file, I have a column with a date formatted as a string.

Using an Excel formula, I want to change the format to a date value.

For this I use the following code:

  // getting the date string and pull out year and month information for further usage
 
  let date_string = selectedSheet.getRange("A2").getValue() as string;
  let jahr_str = date_string.substring(6, 10);
  let monat_str = date_string.substring(3, 4);
  let jahr_int = parseInt(jahr_str);
  let monat_int = parseInt(monat_str);
  let jahr_monat = jahr_str + "_" + monat_str;
 
 
// converting the date and employee id string values into date value and number value via excel formula
  selectedSheet
    .getRange("AR2:AS2")
    .setFormulas([
      [
        '=IF(tblschuiexport[Datum]<>"",DATEVALUE(tblschuiexport[Datum]),"")',
        '=IF(tblschuiexport[Personalnummer]<>"",NUMBERVALUE(tblschuiexport[Personalnummer]),"")',
      ],
    ]);
  // Paste result of conversion into the table
  tblschuiexport
    .getColumn("Datum")
    .getRangeBetweenHeaderAndTotal()
    .getRow(0)
    .copyFrom(
      selectedSheet
        .getRange("AR2:AS2")
        .getExtendedRange(ExcelScript.KeyboardDirection.down),
      ExcelScript.RangeCopyType.values,
      false,
      false
    );
  // Set number format for date column
  tblschuiexport
    .getColumn("Datum")
    .getRangeBetweenHeaderAndTotal()
    .getRow(0)
    .getResizedRange(parseInt(last_row)-1, 0)
    .setNumberFormat("dd.mm.yyyy");
 
Problem: When I run this script in Excel, everything is fine. However, when I run the script with Power Automate, I get a lot of #VALUE errors in the date column.

I assume this is due to different language settings?! But how can I fix this - does anyone have any ideas?

For further understanding I attach two screenshots and an anonymized sample file as well as the office script file.

 
Thanks in advance!!
 
Best Regards,
Peter 
 
Screenshot_after_execution_from_pa.pngImage Enlarger
Screenshot_before_execution_from_pa.pngImage Enlarger
 
sp_PlupAttachments Attachments
  • sp_PlupImage Screenshot_after_execution_from_pa.png (198 KB)
  • sp_PlupImage Screenshot_before_execution_from_pa.png (183 KB)
sp_AnswersTopicSeeAnswer See Answer
Avatar
Velouria
London or thereabouts
Member
Members


Trusted Members
Level 4
Forum Posts: 574
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
2
December 22, 2022 - 8:51 pm
sp_Permalink sp_Print

Instead of using DATEVALUE, I'd suggest using DATE(RIGHT(tblschuiexport[Datum],4),MID(tblschuiexport[Datum],4,2),LEFT(tblschuiexport[Datum],2))

sp_AnswersTopicAnswer
Answers Post
Avatar
Peter Fresh
Member
Members
Level 0
Forum Posts: 13
Member Since:
August 6, 2020
sp_UserOfflineSmall Offline
3
December 22, 2022 - 9:22 pm
sp_Permalink sp_Print

Thanks for the idea to change the way to get the date value.
It just fixed the problem!!!

Avatar
Velouria
London or thereabouts
Member
Members


Trusted Members
Level 4
Forum Posts: 574
Member Since:
November 1, 2018
sp_UserOfflineSmall Offline
4
December 27, 2022 - 9:55 am
sp_Permalink sp_Print

You're welcome, and merry Christmas 🙂

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 170
Currently Online: Norilina Harvel, Jose Molina, Brenda Krol
Guest(s) 56
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1431
Anders Sehlstedt: 848
Velouria: 574
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 213
A.Maurizio: 202
Aye Mu: 201
Jessica Stewart: 185
Newest Members:
David Collins
Andras Marsi
Orimoloye Funsho
YUSUF IMAM KAGARA
PRADEEP PRADHAN
Vicky Otosnika
Abhishek Singh
Kevin Sojourner
Kara Weiss
And Woox
Forum Stats:
Groups: 3
Forums: 24
Topics: 6047
Posts: 26543

 

Member Stats:
Guest Posters: 49
Members: 31497
Moderators: 2
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Riny van Eekelen
© Simple:Press —sp_Information
  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
 
  • About My Online Training Hub
  • Contact
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Copyright © 2023 · My Online Training Hub · All Rights Reserved

Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.

Download A Free Copy of 100 Excel Tips & Tricks

excel tips and tricks ebook

We respect your privacy. We won’t spam you.

x