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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Horizontal Gallery Tem...
Power Apps
Answered

Horizontal Gallery Template Size and Gantt Chart construction

(2) ShareShare
ReportReport
Posted on by 546 Super User 2024 Season 1
I'm putting a Gantt Chart together based on data in a SharePoint list.  In my list, a record has a Start Date and an End Date.  
 
The Horizontal Gallery contains the months that stretch from the earliest activity start date until the month of the latest ending activity.  The Horizontal Gallery contains a nested Vertical gallery which displays the record's Activity name, with the X being calculated on the number of days since the 1st of the earliest month of activities, multiplied by the number of pixels that a day represents.
 
The issue that I have is that since not all months contain the same number of days, if I have a long activity, the length of the activity stretches past the End Date because it's going on the number of days instead of what the calendar looks like.  I hope that makes sense.
 
In this example, Deliverable 4 is showing as stretching into the beginning of Jan 2026, even though the Start Date is 12/01/2024 and End Date for it is 12/31/2025 (duration is 396 days):
 
 
Is there a way to set the widths of the Horizontal gallery to be variable based on the number of days in that month to make the calculation work properly?  Does anyone have a better approach to this?
Categories:
I have the same question (0)
  • Verified answer
    BCBuizer Profile Picture
    22,718 Super User 2026 Season 1 on at
    Hi @zuurg,
     
    The below formula should do the trick for the Width property control inside the vertical gallery that displays the activity name:
    (
    	Day(ThisItem.StartDate) / (EoMonth(ThisItem.StartDate,0)) +
    	(DateDiff(ThisItem.StartDate, ThisItem.EndDate, TimeUnit.Months) - 1) +
    	Day(ThisItem.EndDate) / (EoMonth(ThisItem.EndDate, 0))
    ) * HorizontalGallery.TemplateWidth
     
    This works by adding the fraction of the first month, the number of full months in between the start- and enddate and the fraction of the last month and then multiply this by the width of a month (HorizontalGallery.TemplateWidth). Like this, the number of days in each month becomes irrelevant.
     
     
    If this reply helped you in any way, please give it a Like 💜 and in case it resolved your issue, please mark it as the Verified Answer ✅.
  • zuurg Profile Picture
    546 Super User 2024 Season 1 on at
    Thanks @BCBuizer!
     
    This was still a little off, but the logic behind your solution was exactly what I was looking for by treating the first month, months in between, and last month as 3 separate pieces to add together.
     
    This is what I ended up with:
     
    // Starting Month
       ((DateDiff(ThisItem.'Start Date',EOMonth(ThisItem.'Start Date',0),TimeUnit.Days) + 1) / Day(EOMonth(ThisItem.'Start Date',0))) * gal_MonthYear.TemplateWidth + 
    // Ongoing Months
       (DateDiff(ThisItem.'Start Date',ThisItem.'End Date',TimeUnit.Months) - 1) * gal_MonthYear.TemplateWidth + 
    // Final Month
       Day(ThisItem.'End Date') / Day(EOMonth(ThisItem.'End Date',0)) * gal_MonthYear.TemplateWidth
     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 875

#2
Valantis Profile Picture

Valantis 530

#3
11manish Profile Picture

11manish 432

Last 30 days Overall leaderboard