cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Working out if a date field is formatted correctly

Hi all,

 

I have created a flow which runs once a month. It looks up a table in a spreadsheet, converts it to an HTML table and sends it in the body of an email to certain recipients. Everything works, except the date column. And I suspect it is because users can either enter a date, or just write free text (see screenshot below):

freddiejoseph1_0-1626706911463.png

Below you can see how the entries look in my email body:

freddiejoseph1_1-1626707087820.png

 

So I guess my question is. How do I turn the 5 digit number back into a date format? I assume somehow the date has changed and it now appears as a 5 digit number beginning with a 4?? I only want a date in that column if a date has been entered, otherwise I would like the free text to remain as free text.

 

I assume I would need to wrap the Leaving Date item here in some kind of if statement?

freddiejoseph1_2-1626707328056.png

 

Thanks,

 

Freddie

1 ACCEPTED SOLUTION

Accepted Solutions
eliotcole
Super User
Super User

I'm with you on that mentality, there. Some folks just legacy plop data that should be in a database into Excel ... it's  a calculator, not a rolodex! 😅

 

The simplest solution is to create a hidden helper column in Excel that formats the date into an acceptable format elsewhere.

2021-07-19T15:55:12.6308941Z

yyyy-MM-ddThh:mm:ssZ

Then pick that column out.

 

 

Then create a separate helper column that simply checks for blank entries, and use that to create a boolean in Flow.

 

You could process the empty values, too, though. But it sounds like you'd be good enough to work out that logic.

 

I'll keep looking, though.

 

((( just editing in to say that I've **DEFINITELY** done this before, and worked out an efficient way of handling it that didn't involve extra actions ... the annoying thing is that it might be a formula, in which case it's not really helping the next person that comes to the flow 😞 ... )))

 

Further Edit:
OK, I haven't worked it out yet (I'm no maths wiz), but some of the stuff I did here will maybe help.

 

I would guess that you need to work out whatever the multiplication amount is to multiply the number by, and you'll  ... oh ... something something something maths. 😅

View solution in original post

17 REPLIES 17
eliotcole
Super User
Super User

I believe this is a UNIX date or some other kind, @Anonymous , lemme look it up, quickly. 🙂

 

The usual standard reply that you'll get from the robots here will be something about counting up from 1970 or somesuch ... I'm pretty sure there's a much simpler solution. ( but i've been wrong before XD )

 

Anonymous
Not applicable

Thanks Eliot. I think the number represents the number of days since the date: 1/1/1900

Right, and there's the 'ticks' function which can convert a date *into* that, I'm just trying to grep/remember the reverse of it. Sorry ... again, I could be way off here. But we can all agree it's a pain to draw up logic to work that out every time.

Out of interest, is there a reason why you can't move the datasource to SharePoint, then just export it to excel for the few people that still need an excel sheet? (that isn't a chastisement, just that quite often it's something people just haven't though of or done for a good reason)

Anonymous
Not applicable

No problem at all. Basically, I need to somehow tell the select part of my flow to:

  1. Use the date (if a date has been entered in the spreadsheet)
  2. If no date has been entered then the field be left blank OR use the words/letters that have been entered.

I thought exactly the same thing. Unfortunately the spreadsheet is massive and has loads of tables in it. So it would be very difficult to move them all over to SharePoint. I did suggest we did this because I don't like working with Excel in flow (compared to SharePoint).

eliotcole
Super User
Super User

I'm with you on that mentality, there. Some folks just legacy plop data that should be in a database into Excel ... it's  a calculator, not a rolodex! 😅

 

The simplest solution is to create a hidden helper column in Excel that formats the date into an acceptable format elsewhere.

2021-07-19T15:55:12.6308941Z

yyyy-MM-ddThh:mm:ssZ

Then pick that column out.

 

 

Then create a separate helper column that simply checks for blank entries, and use that to create a boolean in Flow.

 

You could process the empty values, too, though. But it sounds like you'd be good enough to work out that logic.

 

I'll keep looking, though.

 

((( just editing in to say that I've **DEFINITELY** done this before, and worked out an efficient way of handling it that didn't involve extra actions ... the annoying thing is that it might be a formula, in which case it's not really helping the next person that comes to the flow 😞 ... )))

 

Further Edit:
OK, I haven't worked it out yet (I'm no maths wiz), but some of the stuff I did here will maybe help.

 

I would guess that you need to work out whatever the multiplication amount is to multiply the number by, and you'll  ... oh ... something something something maths. 😅

eliotcole
Super User
Super User

It's probably not worth overthinking this.

 

Use Ryan Maclean's (@RyanMaclean365 ?) method, here:
Converting Excel Date Time Serial Values With Power Automate – Ryan Maclean (ryanmaclean365.com)

 

Yep, just tested that and it works perfectly.

 

If you want to make life easy for yourself make a variable to store the excel number in, and replace "triggerBody()['text']" with the variable:

addseconds('1899-12-30',int(formatnumber(mul(float(triggerBody()['text']),86400),'0')))

 

Anonymous
Not applicable

Thanks for getting back to me Eliot. Would you be able to explain a little bit more where/how I do this? I tried using the expression: 

addseconds('1899-12-30',int(formatnumber(mul(float(item)?['Date Leaving']),86400),'0'))) in my select part of my flow and it tells me the expression is invalid. Is this the right place to be trying this expression?
freddiejoseph1_0-1626859008688.png

I am trying to add it into the value field next to the Date Testing key field.

 

Thanks,

 

Freddie

Anonymous
Not applicable

Sorry. Just to add. I have tried using a variable as well. I get the error: Unable to process template language expressions in action 'Set_variable' inputs at line '1' and column '16940': 'The template language function 'float' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'. When I try and set the variable as below.

 

freddiejoseph1_0-1626859628840.png

The expression I have used to set the value of the variable is: 

addSeconds(item()?['Date Leaving'],int(formatNumber(mul(float(item()?['Date Leaving']),'0'))))
 
Any help would be greatly appreciated!
 
Freddie

 

eliotcole
Super User
Super User

It won't work in the variable in that particular method, however, if you persist you should be able to add the expression into the field.

 

Sometimes it will say something is off ... then a few seconds later it accepts it. ¯\_(ツ)_/¯

Lemme test, though.

 

Edited to add: Remember, this isn't my solution, however I don't see why it shouldn't work ... although I'm not sure why the need for the formatNumber part.

 

Also: It looks like you have an erroneous reference to your date in that formula, BTW, plus you also have removed the multiplication.

eliotcole
Super User
Super User

Here's your correct formula for your select, @Anonymous :

addSeconds('1899-12-30', int(formatNumber(mul(float(item()?['Date Leaving']), 86400), '0')))

 

Have tested and seen positive results. 🙂

Anonymous
Not applicable

Hmmm. It still doesn't seem to work. I get the below error. Do you think it could be because in the spreadsheet there are items which aren't a date?

freddiejoseph1_0-1626868376707.png

The execution of template action 'Select' failed: The evaluation of 'query' action 'where' expression '{
"Org Name": "@item()?['Organisation Name and/or Detail']",
"Whole Org": "@item()?['Whole Organisation?']",
"Date Leaving": "@item()?['Date Leaving']",
"Status": "@item()?['Status']",
"Payroll Area": "@item()?['Payroll Area']",
"Contact": "@item()?['Contact']",
"Tupe Out": "@item()?['Tupe Out']",
"Off-Boarding": "@item()?['Off-Boarding']",
"DFE Number": "@item()?['DFE Number']",
"Date Testing": "@addSeconds('1899-12-30', int(formatNumber(mul(float(item()?['Date Leaving']), 86400), '0')))"
}' failed: 'The template language function 'float' was invoked with a parameter that is not valid. The value cannot be converted to the target type.'.

 

If we think that is the problem (I think it is). Is there a way to somehow wrap the expression in an If statement? So if the value in that cell is a date, it does the whole multiplication thing, otherwise it shows the text?

 

Thanks,

 

Freddie

eliotcole
Super User
Super User

 

Do what I did, @Anonymous .

 

Work backwards in the expression:

  1. First add the float(), as that is the first entry.
  2. Then add the mul(), as it's the second.
  3. Then formatNumber().
  4. Then int().
  5. Then addSeconds().

Identify where the issue is in your expression. 🙂

 

It's usually a stray bracket or comma!

 

--------

 

Remember, there's always the easier option of making a helper column in the excel table (that you can hide from users there) which formats the date and time correctly.

 

------

 

Also, what happens when you bring the field over straight, with no formatting or expressions, does it accept it there?

As it might be that the excel sheet is formatting the field as text, rather than a number according to something done on that side.

Anonymous
Not applicable

I think the issue is coming from when a user doesn't enter a date into the spreadsheet and they enter some other text. Like 'TBC' for example. I have now tried to get around that using an If expression but I still can't get that to work.

 

if(startsWith(item()?['Date Leaving'], '4') and (length(item()?['Date Leaving'], '5')), addSeconds('1899-12-30', int(formatNumber(mul(float(item()?['Date Leaving']), 86400) '0', 'dd/MM/YYYY'))), (item()?['Date Leaving'])))

 

Something like the above would check that field to see if it starts with a '4' and has a length of 5 characters (the UNIX date or whatever it is called). If yes, then it carries out the add seconds expression and works out the date, if no, then it just returns whatever is in that field.

 

This still says the expression is invalid 😞

 

Freddie

You could:

  1. Figure out how to handle the NULL or STRING variables (perhaps IF/THEN it to place 01/01/1900 as the date if there's an error).
  2. Or, create an error thread to handle null/strings.

 

Figure out the Expression

On a NULL or STRING replace the value with the date above

 

Error Threading

With error threading ... it's basically two branches, and the second has a "Run after" value of only 'failed'. Meanind it will only run if the SELECT action fails.

 

If you haven't figured something out by tomorrow, hopefully I'll be around and will poke at your variant issues, here.

 

In the meantime, I highly advise that you just create a hidden 'helper column' in the excel sheet to do it there, and just pass perfectly formatted dates across. 🙂

 

 

I mean ... whilst also poking the people that insist on keeping it in excel and not SharePoint 😉.

eliotcole
Super User
Super User

@Anonymous how did you get on with errors?

 

I had a couple more thoughts on those. In excel you can add Data Validation to a field to ensure that they enter the correct information.

 

Another option is to move their *ENTIRE* input mechanism to a Microsoft Forms form. You could have it populate the data in the same spreadsheet, then update the table, accordingly. Or you could capture it in Power Automate, and then handle accordingly. There's a big chance the latter method could negate all this date wrangling, too!

Anonymous
Not applicable

Hey Eliot,

 

Sorry I meant to reply to you last week but completely forgot. I will mark your suggestion of a hidden field in Excel as the solution. Although I didn't use it in the end, I think it will work well. You'd probably need that maybe with a combo of what I ended up doing. I ended up using this expression: 

if(empty(item()?['Date Leaving']),null,if(and(startsWith(item()?['Date Leaving'], '4'),equals(length(item()?['Date Leaving']), 5)),addDays('1899-12-30',int(item()?['Date Leaving']),'dd-MM-yyyy'),item()?['Date Leaving']))
in the select part of my flow and it works perfectly 🙂 freddiejoseph1_0-1627308237713.png

 

 

Thanks very much for all your help and suggestions. I really appreciate it,

 

Freddie

eliotcole
Super User
Super User

Oh, excellent. Don't worry, I'm not fussed about getting points here ... just remembered you whilst handling something else, and wanted to check in! 🙂 Glad it's all good!

Helpful resources

Announcements

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!   Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪 🌠  

Tuesday Tips: Community Ranks and YOU

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!This Week: Community Ranks--Moving from "Member" to "Community Champion"   Have you ever wondered how your fellow community members ascend the ranks within our community? What sets apart an Advocate from a Helper, or a Solution Sage from a Community Champion? In today’s #TuesdayTip, we’re unveiling the secrets and sharing tips to help YOU elevate your ranking—and why it matters to our vibrant communities. Community ranks serve as a window into a member’s role and activity. They celebrate your accomplishments and reveal whether someone has been actively contributing and assisting others. For instance, a Super User is someone who has been exceptionally helpful and engaged. Some ranks even come with special permissions, especially those related to community management. As you actively participate—whether by creating new topics, providing solutions, or earning kudos—your rank can climb. Each time you achieve a new rank, you’ll receive an email notification. Look out for the icon and rank name displayed next to your username—it’s a badge of honor! Fun fact: Your Community Engagement Team keeps an eye on these ranks, recognizing the most passionate and active community members. So shine brightly with valuable content, and you might just earn well-deserved recognition! Where can you see someone’s rank? When viewing a post, you’ll find a member’s rank to the left of their name.Click on a username to explore their profile, where their rank is prominently displayed. What about the ranks themselves? New members start as New Members, progressing to Regular Visitors, and then Frequent Visitors.Beyond that, we have a categorized system: Kudo Ranks: Earned through kudos (teal icons).Post Ranks: Based on your posts (purple icons).Solution Ranks: Reflecting your solutions (green icons).Combo Ranks: These orange icons combine kudos, solutions, and posts. The top ranks have unique names, making your journey even more exciting! So dive in, collect those kudos, share solutions, and let’s see how high you can rank!  🌟 🚀   Check out the Using the Community boards in each of the communities for more helpful information!  Power Apps, Power Automate, Copilot Studio & Power Pages

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

Users online (5,912)