SOLVED

date diff for power auto for 2 column

Copper Contributor

I am creating a flow that will automatically send an email once a week if the dates between 2 columns become < 30 days.

 

I created a switch where if the project is Closed, nothing happens. if it is open it will get the items of the 2 values, but unsure how to do a date diff.

Do i do another switch where if above 30 nothing happens?

 

Also, if I have a switch that if it doesn't match does nothing is there a standard practice to close any potential loops? ty

5 Replies

Wrap both dates on both sides of the conditional with the ticks() function. Ensure the values that you wrap the ticks() function around are timestamps.


For example:

ticks(formatDateTime(variables('Todays Date'), 'yyyy-MM-ddTHH:mm:ss')) is greater(less) than ticks(formatDateTime(variables('The Other Date'), 'yyyy-MM-ddTHH:mm:ss'))

best response confirmed by nerdyplayer (Copper Contributor)
Solution

@nerdyplayer you don't really want a switch for this, a normal condition will work fine.  Where the difference between the start and end date is less than 30 days and the Status is not Closed and the start date is in the future then we send the email, so in my list below this will only be Guadeloupe, Curacao and Aruba.

0-SP.png

 

The flow has a recurrence schedule trigger set to run once a week at 4am on Monday. The get items actin has a filter query so we're only looking at items where the start date is later than today:

 

1-Flow.png

 

Add an apply to each and add 3 compose actions, 1 for the start date, 1 for the end date and one to calculate the difference. The expression for the date difference in days is:

int(split(dateDifference(outputs('ComposeStart'),outputs('ComposeEnd') ), '.')[0])

 

2-Flow.png

 

Then add a condition and select the Outputs of the ComposeDifference compose action is less than 30 and the Status Value is not equal to Closed. Leave the red if no channel empty, but add your email action int the green if yes channel.

 

3-Flow.png

 

This will send the email about each open item where the difference is less than 30 days:

 

4-Email.png

 

There are ways to send just a single email but this should get you going for now.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

 

 

 

 

 

YAY it worked ty.
Question, under get items what is the reasoning behind the filter?

@nerdyplayer it's always more efficient to have a filter query rather than bringing back every item from the list. IN this case I just wanted items with a start date greater than or equal to today.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

Nevermind- I wanted to filter out the columns where the end date was blank.

A colleague suggested I add another condition where end date is equal to true.

1 best response

Accepted Solutions
best response confirmed by nerdyplayer (Copper Contributor)
Solution

@nerdyplayer you don't really want a switch for this, a normal condition will work fine.  Where the difference between the start and end date is less than 30 days and the Status is not Closed and the start date is in the future then we send the email, so in my list below this will only be Guadeloupe, Curacao and Aruba.

0-SP.png

 

The flow has a recurrence schedule trigger set to run once a week at 4am on Monday. The get items actin has a filter query so we're only looking at items where the start date is later than today:

 

1-Flow.png

 

Add an apply to each and add 3 compose actions, 1 for the start date, 1 for the end date and one to calculate the difference. The expression for the date difference in days is:

int(split(dateDifference(outputs('ComposeStart'),outputs('ComposeEnd') ), '.')[0])

 

2-Flow.png

 

Then add a condition and select the Outputs of the ComposeDifference compose action is less than 30 and the Status Value is not equal to Closed. Leave the red if no channel empty, but add your email action int the green if yes channel.

 

3-Flow.png

 

This will send the email about each open item where the difference is less than 30 days:

 

4-Email.png

 

There are ways to send just a single email but this should get you going for now.

 

Rob
Los Gallardos
Microsoft Power Automate Community Super User.
Principal Consultant, SharePoint and Power Platform WSP Global (and classic 1967 Morris Traveller driver)

 

 

 

 

 

View solution in original post