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

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Grouping subtotals and displaying in gallery

(0) ShareShare
ReportReport
Posted on by 170
nsepeWe are building an app that includes financial data for projects.  Based on the selected main project, there can be several financial line items that are tied back to an accounting unit.  I have successfully built out the monthly values based on month, as shown in the graphic.  Each line item includes 60 months (two years back from the current month/year, and two years forward).  This monthly horizontal gallery is embedded into a vertical gallery, which is the main gallery for each finance line item.  Values are patched to a backend SQL table and the mmyyyy value of that template item is the "key" or "id" of that saved monthly financial unit.  Also, each unit contains the Target Value, the Actual Value, and a Forecast Value.
 
What the business partners want now is a subtotal view that sums each month for each line item, for each Expense Type (either OM / Capital).  Something like this:
 
The actual app screenshot is here:
 
I got this from CoPilot, but when I bind MonthlySums to the gallery, I can get each row for Expense Type, but I am not sure how to display each Monthly total.
 
Step 1: Group Records by Category
ClearCollect(
    GroupedRecords,
    AddColumns(
        GroupBy(
            FinanceEntriesForThisWEDB,
            ExpenseType,
            "GroupedItems"
        ),
        "MonthlySums",
        ForAll(
            GroupedItems,
            {
                Month: MonthNumber,
                Year: YearNumber,
                TargetSum: Sum(GroupedItems, Target),
                ActualSum: Sum(GroupedItems, Actual),
                ForecastSum: Sum(GroupedItems, Forecast)
            }
        )
    )
)

Step 2: Sum Monthly Values
ClearCollect(
    MonthlySums,
    AddColumns(
        GroupedRecords,
        "MonthlyTotals",
        ForAll(
            GroupedItems,
            {
                MonthYear: Text(Month) & "/" & Text(Year),
                TargetTotal: Sum(GroupedItems, TargetSum),
                ActualTotal: Sum(GroupedItems, ActualSum),
                ForecastTotal: Sum(GroupedItems, ForecastSum)
            }
        )
    )
)

Step 3: Display Results
  • Bind your gallery to the MonthlySums collection.
  • Use labels to display Category, MonthYear, TargetTotal, ActualTotal, and ForecastTotal.
This should help you get the monthly sum totals separated by category for each target, actual, and forecast value. If you need any further adjustments or run into any issues, feel free to let me know!
Categories:
I have the same question (0)
  • Suggested answer
    CMSGuy Profile Picture
    170 on at
    Grouping subtotals and displaying in gallery
    I was able to do this eventually.  As there are only two expense types: CAP and OM, I am doing two different collections and binding each to a different horizontal gallery.  It is messy, but it does what is needed.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 766 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 419 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 235

Last 30 days Overall leaderboard