web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Get a list of calendar...
Power Automate
Answered

Get a list of calendar events and organize them by day

(1) ShareShare
ReportReport
Posted on by 32

I have a requirement to get a list of events from an outlook calendar for the current month, and organize the events by day.  I have viewed many tutorials and was able to easily find a way to query the calendar using the "Get calendar view of events (V3)" for the month and easily print the monthly calendar in the following format.

MRKennedy_0-1674248644243.png

the flow to create this output is below:

MRKennedy_1-1674248734116.png

The challenge I am facing is that I would like the output to be by day similar to the following format: 

Sunday, January 1st, 2023

Start Time   End Time   Subject

9:00AM       10:00AM     Subject Title 1

10:00AM       11:00AM     Subject Title 2

....   

...

Monday, January 2nd, 2023

Start Time   End Time   Subject

10:00AM       11:00AM     Subject Title 1

....

 

        I realize I can query "Get calendar view of events (V3)" for each day of the month, but that function has a lot of overhead and will be running this flow for multiple calendars, I would like to query the "Get calendar view of events (V3)" once for the month, and then format/parse the data later in the flow to achieve the desired format.  Is there an elegant way to do this?

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this is what you're looking for.

     

    For this example, I've got three events in the current month, two of which are on the same day.

    grantjenkins_0-1674348871706.png

     

    See full flow below. I'll go into each of the actions.

    grantjenkins_2-1674349622272.png

     

    Get calendar view of events retrieves events created this month. Below are the expressions used, which includes converting the current UTC time to my time zone. I've also added an Order By using start/DateTime so the events come back in the correct order.

    //Start Time
    startOfMonth(convertTimeZone(utcNow(), 'utc', 'E. Australia Standard Time'))
    
    //End Time
    startOfMonth(addToTime(convertTimeZone(utcNow(), 'utc', 'E. Australia Standard Time'), 1, 'month'))

    grantjenkins_7-1674351557555.png

     

    Select Events builds up my objects, again converting the UTC dates to my time zone.

    //Start time
    convertTimeZone(item()?['start'], 'utc', 'E. Australia Standard Time')
    
    //End time
    convertTimeZone(item()?['end'], 'utc', 'E. Australia Standard Time')
    
    //Date - will be used to filter the events per day
    convertTimeZone(item()?['start'], 'utc', 'E. Australia Standard Time', 'yyyy-MM-dd')

    grantjenkins_4-1674351159522.png

     

    Select Dates uses the output from Select Events and extracts out just the Date for grouping the events. The expression used is:

    item()?['Date']

    grantjenkins_5-1674351340869.png

     

    Initialize variable HTML creates a new string variable called html that will eventually hold all the tables, etc.

    grantjenkins_6-1674351391494.png

     

    Apply to each iterates through each of the dates. Because we can have multiple events on the same date, we need to remove duplicates using the union expression.

    union(body('Select_Dates'), body('Select_Dates'))

    grantjenkins_8-1674351654016.png

     

    Filter array uses the output from Select Events and the following expression. This will give us all the events for the current date we are iterating over.

    item()?['Date']
    
    //Current Item is:
    items('Apply_to_each')

    grantjenkins_9-1674351745468.png

     

    Append to string variable start adds the current date as a Heading 4 element, then the start of the table. The date is also formatted to look like what you had in your example.

    <h4>@{formatDateTime(items('Apply_to_each'), 'dddd, MMMM d, yyyy')}</h4>
    <table>
     <thead>
     <tr>
     <th>Start Time</th>
     <th>End Time</th>
     <th>Subject</th>
     </tr>
     </thead>
     <tbody>

    grantjenkins_10-1674351913030.png

     

    Apply to each event then iterates over each of the events in the Filter array (events from the current date).

    grantjenkins_11-1674351971309.png

     

    Append to string variable row builds up each of the table rows with the event data. Below are the expressions used:

    formatDateTime(items('Apply_to_each_event')?['Start time'], 'HH:mm tt')
    formatDateTime(items('Apply_to_each_event')?['End time'], 'HH:mm tt')
    items('Apply_to_each_event')?['Subject']

     

    The full input is:

    <tr>
    <td>@{formatDateTime(items('Apply_to_each_event')?['Start time'], 'HH:mm tt')}</td>
    <td>@{formatDateTime(items('Apply_to_each_event')?['End time'], 'HH:mm tt')}</td>
    <td>@{items('Apply_to_each_event')?['Subject']}</td>
    </tr>

    grantjenkins_12-1674352093397.png

     

    After we've built up each of the rows, we use Append to string variable end to add the remaining part of the table.

    </tbody>
    </table>

    grantjenkins_13-1674352186127.png

     

    The html variable will now contain all the html that we need (headers, tables, etc.).

     

    Compose Style is some CSS to make the tables look nicer in the email. I've just used some CSS that I use for a lot of my tables - you might have your own.

    <style>
     table {
     border-collapse: collapse;
     }
     table td,
     table th {
     border: 1px solid #ddd;
     padding: 6px 20px;
     text-align: left;
     }
     table th {
     background-color: #1C6EA4;
     color: white;
     }
    </style>

    grantjenkins_14-1674352283697.png

     

    Send an email uses the output from Compose Style and the html variable content.

    grantjenkins_15-1674352330154.png

     

    The email output in this example is:

    grantjenkins_16-1674352385170.png


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving it a Thumbs Up.

  • MRKennedy Profile Picture
    32 on at

    Your output is exactly what I am looking for, and you are provided exceptional instructions.  However, I am getting the error that is likely "user error" but over the last hour, I can't resolve it: 

     

    "Unable to process template language expressions in action 'Append_to_string_variable' inputs at line '0' and column '0': 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Object'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'."

     

    At the following step: 

     

    MRKennedy_2-1674395656427.png

     

    This is my code in the expression: "formatDateTime(items('Apply_to_each'), 'dddd, MMMM d, yyyy')"

     

    Any idea why it's returning an object versus a string?

     

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    @MRKennedy For your Select Dates, are you setting the Map to Text mode? See arrow on screenshot.

     

    grantjenkins_1-1674396676846.png

  • MRKennedy Profile Picture
    32 on at

    Yes, I have tried using both options.   It appears my "Filter array" is producing zero output.

    MRKennedy_0-1674410426972.png

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    It looks like you're adding your expressions as plain text. See screenshot below on how to add the expressions.

     

    grantjenkins_0-1674478850399.png

  • MRKennedy Profile Picture
    32 on at

    First, thank you for all of your help!  This morning, I started from scratch and recreated the flow using the directions you initially provided to ensure I did not "fat finger" something and I used the dialog as shown above.  However, I still receive the same error in the same location as above.  are there any screen capture, error logs I can post to assist with the troubleshooting?  Clearly it works, as you were able to generate  my desired output.  But I am not sure what I am doing wrong.

    Thank you again in advance!

  • MRKennedy Profile Picture
    32 on at

    @grantjenkins Any other suggestions? Or things that I may be able to try to get past this error?

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Are you able to provide screenshots of your entire flow similar to how I've added mine so I can see where you may have gone wrong.

  • MRKennedy Profile Picture
    32 on at

    I was able to get it working!  Your instructions were perfect - thank you!

  • MordyHackel Profile Picture
    2 on at

    thank you both!!

    I really appreciate this post and exchange - I happen to need exactly this as well.  I'm also getting the "Unable to process template language expressions in action 'Append_to_string_variable'.........." error.  If either of you would be open to sharing how that was solved, I would appreciate it very much.

    again - thank you!!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 503 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 321 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard