You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[$175] Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all #104993
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorNeeds ReproductionReproducible steps neededWeeklyKSv2
Version Number: Reproducible in staging?: Needs Reproduction (Unable to reproduce) Reproducible in production?: Needs Reproduction If this was caught during regression testing, add the test name, ID and link from BrowserStack: Email or phone of affected tester (no customers): Logs:https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by:@FitseTLT Slack conversation (hyperlinked to channel name): #Expensify Bugs
Action Performed:
Use an account with a large number of expenses.
Go to Spend > Reports.
Apply the filter total:>0 (to exclude negative totals).
Select all expenses matching the filter.
Observe the displayed selected total.
Expected Result:
The selected total should reflect the actual sum of all expenses matching total:>0 — a positive amount roughly consistent with the number of matching expenses and their individual totals.
Actual Result:
The selected total shows $0.02 — a value far lower than expected, and even lower than the sum shown when only selecting all expenses on the current page (not the full filtered result set).
Workaround:
Unknown
Platforms:
Select the officially supported platforms where the issue was reproduced:
⚠️Preliminary analysis (low confidence) — treat as a starting point, not a conclusion.
I think the wrong total comes from the backend, not the App. When you select all matching items, the footer does no math of its own. It shows the total the backend returns for the search (SearchSelectionFooter.tsx:812-816). A page-only selection is summed in the App from the loaded rows, which is why that number looks right.
The App sends total:>0 to the backend unchanged, as gt 0 cents with no sign flip (SearchQueryUtils.ts:868-881). Rows and totals come from the same Search request with the same filters. My best guess is that the backend's totals step applies total>0 differently from the row filter. For example, it may filter per transaction or use the opposite sign of the stored report total. That would leave only a few small positive items, such as $0.02.
One App-side factor may contribute. On a Reports select-all, every next-page request also asks for totals (Search/index.tsx:232, :1063). Each response overwrites the snapshot total. The Expenses view asks for totals only on the first page (useSearchShouldCalculateTotals.ts). If the backend computes totals only from rows at or after the offset, scrolling would shrink the footer total.
I couldn't verify this. The issue has no account or request IDs, and the bug needs an account with many expenses. To confirm, compare the Search responses for the affected account:
If the offset=0 response already returns search.total ≈ 2 cents, the backend totals step is wrong. An internal engineer needs to fix it outside the App repo.
If only offset>0 responses return the small total, the App should also stop asking for totals after page 1 on Reports select-all.
changed the title [-]Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all[/-][+][$175] Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all[/+]on Oct 26, 2026
Please re-state the problem that we are trying to solve in this issue.
On Spend > Reports (type:expense-report), when filtering by total:>0 (Total: Greater than 0.00) on an account with multiple pages of reports:
Selecting all reports on the current page (Select all on this page, 50 reports) displays the expected positive sum in the footer (Reports: 50 | Total spend: $9,153.30).
Selecting all matching reports across all pages (Select all, 471 reports) displays an incorrect near-zero total (Reports: 471 | Total spend: $0.02).
What is the root cause of that problem?
There are two distinct layers involved when switching from Select all on this page to Select all on Spend > Reports (type:expense-report):
Primary cause at offset = 0 (Backend Search aggregate search.total for type:expense-report + total>0):
Before selecting anything on Spend > Reports (searchKey=reports), useSearchShouldCalculateTotals (src/hooks/useSearchShouldCalculateTotals.ts:37-51) returns false because CONST.SEARCH.SEARCH_KEYS.REPORTS is not in eligibleSearchKeys. The initial Search request at offset: 0 is sent with shouldCalculateTotals: false.
When the user clicks Select all on this page (50 reports), areAllMatchingItemsSelected is false and hasPartialSelection (src/components/Search/SearchSelectionFooter.tsx:406) is true. Therefore shouldUseClientTotal (line 442) is true, and SearchSelectionFooter.tsx:752-766 sums the 50 loaded rows on the client via getEntrySource(transaction) ($9,153.30).
When the user clicks Select all (without scrolling, still at offset = 0), selectAllMatchingItems(true) (src/components/Search/SearchSelectionProvider.tsx:207-218) sets areAllMatchingItemsSelected = true and clears excludedTransactions = {}.
In src/components/Search/index.tsx:232, shouldCalculateTotals flips from false to true, which triggers the useEffect at lines 499-507 to call handleSearch({ ..., offset: 0, shouldCalculateTotals: true }).
Once the response arrives with search.reportCount = 471 and search.count, hasPartialSelection becomes false and shouldUseClientTotal becomes false. With excludedTransactions = {}, SearchSelectionFooter.tsx:812-816 renders metadataTotal - excludedTotal = searchResults.search.total - 0 directly. Because the backend's totals calculation for type:expense-report with total>0 returns search.total = 2 ($0.02), the footer displays $0.02.
App-side asymmetry in src/components/Search/index.tsx for type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT select-all totals & pagination:
Because isExpenseAllMatchingSelection only checks type === CONST.SEARCH.DATA_TYPES.EXPENSE:
Every pagination request (offset > 0) on Reports with Select all active sends shouldCalculateTotals: true: Unlike EXPENSE (which only enables shouldCalculateTotals when offset === 0 || isAllMatchingItemsCountMissing), EXPENSE_REPORT sets shouldCalculateTotals = true unconditionally whenever areAllMatchingItemsSelected is true, so every fetchMoreResults call (line 1064) and offset change (line 503) re-requests totals at offset > 0 and overwrites the snapshot's search.total.
Even for EXPENSE, the first pagination request (0 -> 50) in fetchMoreResults (line 1064) sends shouldCalculateTotals: true:fetchMoreResults calls setOffset(nextOffset) and handleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals }) in the same callback while offset in the current render closure is still 0, so shouldCalculateNextPageTotals is still true for the nextOffset = 50 request.
Missing-count offset clamping and transition guards (lines 236, 479-492) ignore EXPENSE_REPORT (reportCount):getSearchRequestOffsetForMissingAllMatchingCount, didJustFinishAllMatchingTotalsRequest, and didEnableAllMatchingTotalsWithExistingCount all check isExpenseAllMatchingSelection and search.count instead of isRequiredAllMatchingTotalMissing (reportCount for EXPENSE_REPORT).
What changes do you think we should make in order to solve the problem?
Backend (Expensify/Auth / Web-Expensify):
Fix the Search totals aggregation for type:expense-report when filtering on total (e.g. total>0) so search.total aggregates the report totals of the same filtered report set that produces search.reportCount and the returned report rows.
Unify all-matching totals handling across both EXPENSE and EXPENSE_REPORT using isRequiredAllMatchingTotalMissing (typeof searchResults?.search?.reportCount !== 'number' for EXPENSE_REPORT, typeof searchResults?.search?.count !== 'number' for EXPENSE):
Update didJustFinishAllMatchingTotalsRequest and didEnableAllMatchingTotalsWithExistingCount (lines 479-492) to use isAllMatchingSelectionWithTotals and !isRequiredAllMatchingTotalMissing so EXPENSE_REPORT also stops re-requesting totals on offset > 0 once reportCount and total have been fetched at offset === 0.
What alternative solutions did you explore? (Optional)
Summing selectedTransactions on the client when areAllMatchingItemsSelected is true: Not viable because selectedTransactions only contains rows from pages already loaded into the client snapshot (50 reports on page 1, not all 471 matching reports across unloaded pages).
I dug into the code to trace why page 1 sums fine while "Select all" drops to $0.02.
This comes directly from the backend aggregation query in Web-Secure, not NewDot.
Here is what happens under the hood:
Page 1 works locally: Selecting only page 1 sums loaded rows in the client. TransactionUtils inverts the negative database amounts to show positive values (return amount ? -amount : 0). This gives the expected positive sum.
Select all drops client math: When you select all matching items across pages, shouldUseClientTotal in SearchSelectionFooter.tsx turns false. The App stops doing math locally. It shows searchResults.search.total sent by the server.
Backend query sign mismatch: The backend stores expense report totals as negative numbers. When we pass total:>0, the backend aggregation query evaluates total > 0 against the raw signed database column. Normal expense reports are negative, so the query skips them. Only tiny credit adjustments or refund transactions match total > 0, summing to $0.02.
The frontend cannot fix this cleanly. NewDot cannot load hundreds of off-page rows into memory just to sum them in the footer. Any client-side workaround would be a band-aid. The fix needs to happen in the backend search aggregation logic.
@Ollyws this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
Please re-state the problem that we are trying to solve in this issue.
On Spend > Reports (type:expense-report) and Spend > Expenses (type:expense) on an account with multiple pages of matching items, when filtering by total:>0 (Total: Greater than 0.00) and selecting all items on the current page (Select all on this page), the footer displays the expected positive total (e.g. $9,153.30). However, when clicking Select all to select all matching items across all pages (e.g. 471 reports), the displayed Total spend in the footer drops to an incorrect near-zero value ($0.02).
What is the root cause of that problem?
When only the current page is selected (areAllMatchingItemsSelected === false, hasPartialSelection === true), src/components/Search/SearchSelectionFooter.tsx:409, 486-519 sets shouldUseClientTotal = true and sums the loaded rows on the client via acc - (convertedAmount ?? getEntrySource(transaction)), where getEntrySource (lines 124-131) returns the expense-signed (negative) amount so subtracting it yields the positive spend total.
When the user switches to Select all across all pages (areAllMatchingItemsSelected === true, excludedTransactions === {}), hasPartialSelection becomes false, shouldUseClientTotal becomes false, and SearchSelectionFooter.tsx:565-569 renders metadataTotal - excludedTotal (searchResults?.search?.total) directly.
There are two coupled root causes—one in Expensify/App's pagination/totals request gating and one in the backend Search totals aggregation:
constisExpenseAllMatchingSelection=type===CONST.SEARCH.DATA_TYPES.EXPENSE&&areAllMatchingItemsSelected;constisAllMatchingItemsCountMissing=isExpenseAllMatchingSelection&&typeofsearchResults?.search?.count!=='number';constshouldCalculateExpenseTotals=useSearchShouldCalculateTotals(currentSearchKey,offset===0||isAllMatchingItemsCountMissing,isExpenseAllMatchingSelection);constshouldCalculateTotals=(areAllMatchingItemsSelected&&!isExpenseAllMatchingSelection)||shouldCalculateExpenseTotals;// Live to-do pages load without totals. A response with totals restarts the counted reports, so a later page would drop page 1's.constshouldCalculateNextPageTotals=shouldCalculateTotals&&!shouldUseLiveData;
Asymmetric EXPENSE_REPORT handling (lines 243-246, 514-527): Because isExpenseAllMatchingSelection only checks type === CONST.SEARCH.DATA_TYPES.EXPENSE, on Spend > Reports (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) (areAllMatchingItemsSelected && !isExpenseAllMatchingSelection) evaluates to true at every offset (not just offset === 0). As noted by the comment at line 247 ("A response with totals restarts the counted reports, so a later page would drop page 1's"), every pagination request (offset > 0) sends shouldCalculateTotals: true and overwrites the snapshot's search.total with the tail page's total.
First pagination step (0 -> 50) in fetchMoreResults (lines 1112, 1133-1141) sends shouldCalculateTotals: true even on EXPENSE: When the user is at offset === 0 with areAllMatchingItemsSelected === true, shouldCalculateTotals and shouldCalculateNextPageTotals are true in the current render closure. When fetchMoreResults runs for nextOffset = 50, it calls handleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals }) using that closure's true value, so the offset: 50 request is sent with shouldCalculateTotals: true and overwrites page 1's search.total.
Offset clamping when selecting all after scrolling (useSearchShouldCalculateTotals.ts:9-14 & SearchSelectionFooter.tsx:766, 789): In src/hooks/useSearchShouldCalculateTotals.ts:9-14, getSearchRequestOffsetForMissingAllMatchingCount returns Math.min(offset, serverOffset ?? offset). If the user has already scrolled to offset = 50 (serverOffset = 50) before clicking Select all, Math.min(50, 50) returns 50 instead of 0, requesting all-matching totals from offset: 50. Likewise, SearchSelectionFooter.tsx:766, 789 passes offset: metadata?.offset ?? 0 with shouldCalculateTotals: true.
Backend Search totals aggregation sign mismatch on total:>0:
Because standard expenses and expense reports store spend as negative integer cents in the database (while positive values represent credits/refunds or rounding adjustments), when the backend Search totals query evaluates total > 0 against the raw signed column without the spend sign normalization used by the row filter, normal expense reports are excluded from search.total and only tiny positive-signed entries (2 cents = $0.02) are summed.
What changes do you think we should make in order to solve the problem?
constisAllMatchingSelectionWithTotals=(type===CONST.SEARCH.DATA_TYPES.EXPENSE||isExpenseReportType)&&areAllMatchingItemsSelected;constisRequiredAllMatchingTotalMissing=isExpenseReportType&&areAllMatchingItemsSelected ? typeofsearchResults?.search?.reportCount!=='number' : typeofsearchResults?.search?.count!=='number';constisAllMatchingItemsCountMissing=isAllMatchingSelectionWithTotals&&isRequiredAllMatchingTotalMissing;constshouldCalculateExpenseTotals=useSearchShouldCalculateTotals(currentSearchKey,offset===0||isAllMatchingItemsCountMissing,isAllMatchingSelectionWithTotals);constshouldCalculateTotals=(areAllMatchingItemsSelected&&!isAllMatchingSelectionWithTotals)||shouldCalculateExpenseTotals;// Live to-do pages load without totals. A response with totals restarts the counted reports, so a later page would drop page 1's.// Pagination requests (nextOffset > 0) must only request totals when the all-matching count/total is still missing.constshouldCalculateNextPageTotals=useSearchShouldCalculateTotals(currentSearchKey,isAllMatchingItemsCountMissing,isAllMatchingSelectionWithTotals)&&!shouldUseLiveData;
Update comingBackOnlineWithMissingAllMatchingTotals (line 481), didJustFinishAllMatchingTotalsRequest (lines 514-520), and didEnableAllMatchingTotalsWithExistingCount (lines 523-525) to use isAllMatchingSelectionWithTotals and !isRequiredAllMatchingTotalMissing instead of isExpenseAllMatchingSelection and typeof searchResults?.search?.count === 'number'.
When isAllMatchingItemsCountMissing is true, ensure the totals request is anchored so a full-search total is not computed starting from a paginated serverOffset > 0.
Backend (Expensify/Auth / Web-Expensify):
Ensure the Search totals aggregation applies the total filter (total:>0) with the exact same spend sign normalization as the row query so search.total at offset: 0 sums all matching reports/expenses.
What alternative solutions did you explore? (Optional)
Falling back to clientTotal in SearchSelectionFooter.tsx when areAllMatchingItemsSelected is true: Rejected because selectedTransactions only holds rows from the pages loaded into the client snapshot so far (e.g. 50 reports on page 1 out of 471 matching reports across all pages), so multi-page select-all must use search.total computed at offset: 0 and keep offset > 0 pagination requests from overwriting it.
BugSomething is broken. Auto assigns a BugZero manager.ExternalAdded to denote the issue can be worked on by a contributorNeeds ReproductionReproducible steps neededWeeklyKSv2
Activity
FitseTLT commentedon Oct 26, 2026
cc @JS00001 most probably a BE bug
MelvinBot commentedon Oct 26, 2026
I think the wrong total comes from the backend, not the App. When you select all matching items, the footer does no math of its own. It shows the
totalthe backend returns for the search (SearchSelectionFooter.tsx:812-816). A page-only selection is summed in the App from the loaded rows, which is why that number looks right.The App sends
total:>0to the backend unchanged, asgt 0cents with no sign flip (SearchQueryUtils.ts:868-881). Rows and totals come from the sameSearchrequest with the same filters. My best guess is that the backend's totals step appliestotal>0differently from the row filter. For example, it may filter per transaction or use the opposite sign of the stored report total. That would leave only a few small positive items, such as $0.02.One App-side factor may contribute. On a Reports select-all, every next-page request also asks for totals (
Search/index.tsx:232,:1063). Each response overwrites the snapshot total. The Expenses view asks for totals only on the first page (useSearchShouldCalculateTotals.ts). If the backend computes totals only from rows at or after the offset, scrolling would shrink the footer total.I couldn't verify this. The issue has no account or request IDs, and the bug needs an account with many expenses. To confirm, compare the
Searchresponses for the affected account:offset=0response already returnssearch.total≈ 2 cents, the backend totals step is wrong. An internal engineer needs to fix it outside the App repo.offset>0responses return the small total, the App should also stop asking for totals after page 1 on Reports select-all.Possibly related: [Due for payment 2026-10-22] Add count and spend total selectors to the Spend footer to let customers choose the data they see, which recently reworked this footer.
Next Steps: Reply with
@MelvinBot <your feedback>to refine this analysis.view run
melvin-bot commentedon Oct 26, 2026
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (
External)[-]Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all[/-][+][$175] Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all[/+]melvin-bot commentedon Oct 26, 2026
Job added to Upwork: https://www.upwork.com/jobs/~022114689088128858232
shilo1979jk commentedon Oct 26, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On
Spend > Reports(type:expense-report), when filtering bytotal:>0(Total: Greater than 0.00) on an account with multiple pages of reports:Select all on this page, 50 reports) displays the expected positive sum in the footer (Reports: 50 | Total spend: $9,153.30).Select all, 471 reports) displays an incorrect near-zero total (Reports: 471 | Total spend: $0.02).What is the root cause of that problem?
There are two distinct layers involved when switching from
Select all on this pagetoSelect allonSpend > Reports(type:expense-report):Primary cause at
offset = 0(BackendSearchaggregatesearch.totalfortype:expense-report+total>0):Spend > Reports(searchKey=reports),useSearchShouldCalculateTotals(src/hooks/useSearchShouldCalculateTotals.ts:37-51) returnsfalsebecauseCONST.SEARCH.SEARCH_KEYS.REPORTSis not ineligibleSearchKeys. The initialSearchrequest atoffset: 0is sent withshouldCalculateTotals: false.Select all on this page(50 reports),areAllMatchingItemsSelectedisfalseandhasPartialSelection(src/components/Search/SearchSelectionFooter.tsx:406) istrue. ThereforeshouldUseClientTotal(line 442) istrue, andSearchSelectionFooter.tsx:752-766sums the 50 loaded rows on the client viagetEntrySource(transaction)($9,153.30).Select all(without scrolling, still atoffset = 0),selectAllMatchingItems(true)(src/components/Search/SearchSelectionProvider.tsx:207-218) setsareAllMatchingItemsSelected = trueand clearsexcludedTransactions = {}.src/components/Search/index.tsx:232,shouldCalculateTotalsflips fromfalsetotrue, which triggers theuseEffectatlines 499-507to callhandleSearch({ ..., offset: 0, shouldCalculateTotals: true }).search.reportCount = 471andsearch.count,hasPartialSelectionbecomesfalseandshouldUseClientTotalbecomesfalse. WithexcludedTransactions = {},SearchSelectionFooter.tsx:812-816rendersmetadataTotal - excludedTotal=searchResults.search.total - 0directly. Because the backend's totals calculation fortype:expense-reportwithtotal>0returnssearch.total = 2($0.02), the footer displays$0.02.App-side asymmetry in
src/components/Search/index.tsxfortype === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORTselect-all totals & pagination:src/components/Search/index.tsx:229-243:isExpenseAllMatchingSelectiononly checkstype === CONST.SEARCH.DATA_TYPES.EXPENSE:offset > 0) onReportswithSelect allactive sendsshouldCalculateTotals: true: UnlikeEXPENSE(which only enablesshouldCalculateTotalswhenoffset === 0 || isAllMatchingItemsCountMissing),EXPENSE_REPORTsetsshouldCalculateTotals = trueunconditionally wheneverareAllMatchingItemsSelectedistrue, so everyfetchMoreResultscall (line 1064) andoffsetchange (line 503) re-requests totals atoffset > 0and overwrites the snapshot'ssearch.total.EXPENSE, the first pagination request (0 -> 50) infetchMoreResults(line 1064) sendsshouldCalculateTotals: true:fetchMoreResultscallssetOffset(nextOffset)andhandleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals })in the same callback whileoffsetin the current render closure is still0, soshouldCalculateNextPageTotalsis stilltruefor thenextOffset = 50request.lines 236, 479-492) ignoreEXPENSE_REPORT(reportCount):getSearchRequestOffsetForMissingAllMatchingCount,didJustFinishAllMatchingTotalsRequest, anddidEnableAllMatchingTotalsWithExistingCountall checkisExpenseAllMatchingSelectionandsearch.countinstead ofisRequiredAllMatchingTotalMissing(reportCountforEXPENSE_REPORT).What changes do you think we should make in order to solve the problem?
Backend (
Expensify/Auth/ Web-Expensify):Searchtotals aggregation fortype:expense-reportwhen filtering ontotal(e.g.total>0) sosearch.totalaggregates the report totals of the same filtered report set that producessearch.reportCountand the returned report rows.App-side hardening in
src/components/Search/index.tsxandlines 479-492, 1064:EXPENSEandEXPENSE_REPORTusingisRequiredAllMatchingTotalMissing(typeof searchResults?.search?.reportCount !== 'number'forEXPENSE_REPORT,typeof searchResults?.search?.count !== 'number'forEXPENSE):didJustFinishAllMatchingTotalsRequestanddidEnableAllMatchingTotalsWithExistingCount(lines 479-492) to useisAllMatchingSelectionWithTotalsand!isRequiredAllMatchingTotalMissingsoEXPENSE_REPORTalso stops re-requesting totals onoffset > 0oncereportCountandtotalhave been fetched atoffset === 0.What alternative solutions did you explore? (Optional)
selectedTransactionson the client whenareAllMatchingItemsSelectedistrue: Not viable becauseselectedTransactionsonly contains rows from pages already loaded into the client snapshot (50 reports on page 1, not all 471 matching reports across unloaded pages).JS00001 commentedon Oct 26, 2026
Yeah I'll take a look at this
JS00001 commentedon Oct 27, 2026
Pinged the contributors to see if they can repro this either
mkhutornyi commentedon Oct 27, 2026
I am not able to reproduce.
Btw the bug is not clear from the video. Footer is cut off so I cannot see the values.
21 remaining items
jeffrey-graham commentedon Nov 7, 2026
melvin-bot commentedon Nov 7, 2026
samithreddychinni commentedon Nov 8, 2026
cc @JS00001 @FitseTLT @Ollyws
I dug into the code to trace why page 1 sums fine while "Select all" drops to $0.02.
This comes directly from the backend aggregation query in Web-Secure, not NewDot.
Here is what happens under the hood:
Page 1 works locally: Selecting only page 1 sums loaded rows in the client.
TransactionUtilsinverts the negative database amounts to show positive values (return amount ? -amount : 0). This gives the expected positive sum.Select all drops client math: When you select all matching items across pages,
shouldUseClientTotalinSearchSelectionFooter.tsxturns false. The App stops doing math locally. It showssearchResults.search.totalsent by the server.Backend query sign mismatch: The backend stores expense report totals as negative numbers. When we pass
total:>0, the backend aggregation query evaluatestotal > 0against the raw signed database column. Normal expense reports are negative, so the query skips them. Only tiny credit adjustments or refund transactions matchtotal > 0, summing to $0.02.The frontend cannot fix this cleanly. NewDot cannot load hundreds of off-page rows into memory just to sum them in the footer. Any client-side workaround would be a band-aid. The fix needs to happen in the backend search aggregation logic.
melvin-bot commentedon Nov 9, 2026
@Ollyws this issue was created 2 weeks ago. Are we close to approving a proposal? If not, what's blocking us from getting this issue assigned? Don't hesitate to create a thread in #expensify-open-source to align faster in real time. Thanks!
melvin-bot commentedon Nov 10, 2026
@Ollyws Huh... This is 4 days overdue. Who can take care of this?
melvin-bot commentedon Nov 12, 2026
@Ollyws 6 days overdue. This is scarier than being forced to listen to Vogon poetry!
cocvn157 commentedon Nov 14, 2026
Proposal
Please re-state the problem that we are trying to solve in this issue.
On Spend > Reports (
type:expense-report) and Spend > Expenses (type:expense) on an account with multiple pages of matching items, when filtering bytotal:>0(Total: Greater than 0.00) and selecting all items on the current page (Select all on this page), the footer displays the expected positive total (e.g.$9,153.30). However, when clicking Select all to select all matching items across all pages (e.g.471reports), the displayed Total spend in the footer drops to an incorrect near-zero value ($0.02).What is the root cause of that problem?
When only the current page is selected (
areAllMatchingItemsSelected === false,hasPartialSelection === true),src/components/Search/SearchSelectionFooter.tsx:409, 486-519setsshouldUseClientTotal = trueand sums the loaded rows on the client viaacc - (convertedAmount ?? getEntrySource(transaction)), wheregetEntrySource(lines124-131) returns the expense-signed (negative) amount so subtracting it yields the positive spend total.When the user switches to Select all across all pages (
areAllMatchingItemsSelected === true,excludedTransactions === {}),hasPartialSelectionbecomesfalse,shouldUseClientTotalbecomesfalse, andSearchSelectionFooter.tsx:565-569rendersmetadataTotal - excludedTotal(searchResults?.search?.total) directly.There are two coupled root causes—one in
Expensify/App's pagination/totals request gating and one in the backendSearchtotals aggregation:Client-side pagination and
EXPENSE_REPORTtotals gating insrc/components/Search/index.tsx:243-258,lines 514-527, andlines 1112, 1138:EXPENSE_REPORThandling (lines 243-246, 514-527): BecauseisExpenseAllMatchingSelectiononly checkstype === CONST.SEARCH.DATA_TYPES.EXPENSE, on Spend > Reports (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT)(areAllMatchingItemsSelected && !isExpenseAllMatchingSelection)evaluates totrueat everyoffset(not justoffset === 0). As noted by the comment at line247("A response with totals restarts the counted reports, so a later page would drop page 1's"), every pagination request (offset > 0) sendsshouldCalculateTotals: trueand overwrites the snapshot'ssearch.totalwith the tail page's total.0 -> 50) infetchMoreResults(lines 1112, 1133-1141) sendsshouldCalculateTotals: trueeven onEXPENSE: When the user is atoffset === 0withareAllMatchingItemsSelected === true,shouldCalculateTotalsandshouldCalculateNextPageTotalsaretruein the current render closure. WhenfetchMoreResultsruns fornextOffset = 50, it callshandleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals })using that closure'struevalue, so theoffset: 50request is sent withshouldCalculateTotals: trueand overwrites page 1'ssearch.total.useSearchShouldCalculateTotals.ts:9-14&SearchSelectionFooter.tsx:766, 789): Insrc/hooks/useSearchShouldCalculateTotals.ts:9-14,getSearchRequestOffsetForMissingAllMatchingCountreturnsMath.min(offset, serverOffset ?? offset). If the user has already scrolled tooffset = 50(serverOffset = 50) before clicking Select all,Math.min(50, 50)returns50instead of0, requesting all-matching totals fromoffset: 50. Likewise,SearchSelectionFooter.tsx:766, 789passesoffset: metadata?.offset ?? 0withshouldCalculateTotals: true.Backend
Searchtotals aggregation sign mismatch ontotal:>0:src/libs/SearchQueryUtils.ts:885-898(getUpdatedFilterValue) serializestotal:>0asoperator: "gt", value: "0"without sign inversion.Searchtotals query evaluatestotal > 0against the raw signed column without the spend sign normalization used by the row filter, normal expense reports are excluded fromsearch.totaland only tiny positive-signed entries (2cents =$0.02) are summed.What changes do you think we should make in order to solve the problem?
Unify all-matching totals gating across
EXPENSEandEXPENSE_REPORTand preventoffset > 0pagination requests from recalculating totals insrc/components/Search/index.tsx:243-258, 481, 514-527:comingBackOnlineWithMissingAllMatchingTotals(line 481),didJustFinishAllMatchingTotalsRequest(lines 514-520), anddidEnableAllMatchingTotalsWithExistingCount(lines 523-525) to useisAllMatchingSelectionWithTotalsand!isRequiredAllMatchingTotalMissinginstead ofisExpenseAllMatchingSelectionandtypeof searchResults?.search?.count === 'number'.Clamp missing all-matching count/total requests to
offset: 0insrc/hooks/useSearchShouldCalculateTotals.ts:9-14:isAllMatchingItemsCountMissingistrue, ensure the totals request is anchored so a full-search total is not computed starting from a paginatedserverOffset > 0.Backend (
Expensify/Auth/Web-Expensify):Searchtotals aggregation applies thetotalfilter (total:>0) with the exact same spend sign normalization as the row query sosearch.totalatoffset: 0sums all matching reports/expenses.What alternative solutions did you explore? (Optional)
clientTotalinSearchSelectionFooter.tsxwhenareAllMatchingItemsSelectedistrue: Rejected becauseselectedTransactionsonly holds rows from the pages loaded into the client snapshot so far (e.g. 50 reports on page 1 out of 471 matching reports across all pages), so multi-page select-all must usesearch.totalcomputed atoffset: 0and keepoffset > 0pagination requests from overwriting it.expensify-chore-bot commentedon Nov 18, 2026
@Ollyws 12 days overdue now... This issue's end is nigh!
expensify-chore-bot commentedon Nov 23, 2026
@Ollyws this issue is now 4 weeks old, please consider:
Thanks!
expensify-chore-bot commentedon Nov 23, 2026
This issue has not been updated in over 14 days. @Ollyws eroding to Weekly issue.