[$175] Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all
If you haven’t already, check out our contributing guidelines for onboarding. To join our Slack channel, fill out this form.
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:
- [ ] Android: App
- [ ] Android: mWeb Chrome
- [ ] iOS: App
- [ ] iOS: mWeb Safari
- [ ] iOS: mWeb Chrome
- [x] Windows: Chrome
- [x] MacOS: Chrome / Safari
Screenshots/Videos
https://github.com/user-attachments/assets/7a5d851c-bcda-4b81-9c88-2ada2b24db73
Upwork Automation - Do Not Edit
- Upwork Job URL: https://www.upwork.com/jobs/~022114689088128858232
- Upwork Job ID: 2114689088128858232
- Last Price Increase: 2026-10-26
cc @JS00001 most probably a BE bug
⚠️ 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=0response already returnssearch.total≈ 2 cents, the backend totals step is wrong. An internal engineer needs to fix it outside the App repo. - If only
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.
Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (External)
Job added to Upwork: https://www.upwork.com/jobs/~022114689088128858232
Proposal
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(BackendSearchaggregatesearch.totalfortype:expense-report+total>0):- Before selecting anything on
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. - When the user clicks
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). - When the user clicks
Select all(without scrolling, still atoffset = 0),selectAllMatchingItems(true)(src/components/Search/SearchSelectionProvider.tsx:207-218) setsareAllMatchingItemsSelected = trueand clearsexcludedTransactions = {}. - In
src/components/Search/index.tsx:232,shouldCalculateTotalsflips fromfalsetotrue, which triggers theuseEffectatlines 499-507to callhandleSearch({ ..., offset: 0, shouldCalculateTotals: true }). - Once the response arrives with
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.
- Before selecting anything on
-
App-side asymmetry in
src/components/Search/index.tsxfortype === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORTselect-all totals & pagination:- In
src/components/Search/index.tsx:229-243:const isExpenseAllMatchingSelection = type === CONST.SEARCH.DATA_TYPES.EXPENSE && areAllMatchingItemsSelected; const isAllMatchingItemsCountMissing = isExpenseAllMatchingSelection && typeof searchResults?.search?.count !== 'number'; const shouldCalculateExpenseTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isExpenseAllMatchingSelection); const shouldCalculateTotals = (areAllMatchingItemsSelected && !isExpenseAllMatchingSelection) || shouldCalculateExpenseTotals; const shouldCalculateNextPageTotals = shouldCalculateTotals && !shouldUseLiveData; const previousShouldCalculateTotals = usePrevious(shouldCalculateTotals); const searchRequestOffset = getSearchRequestOffsetForMissingAllMatchingCount(offset, searchResults?.search?.offset, isAllMatchingItemsCountMissing); const isRequiredAllMatchingTotalMissing = isExpenseReportType && areAllMatchingItemsSelected ? typeof searchResults?.search?.reportCount !== 'number' : searchResults?.search?.count === undefined; - Because
isExpenseAllMatchingSelectiononly checkstype === CONST.SEARCH.DATA_TYPES.EXPENSE:- Every pagination request (
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. - Even for
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. - Missing-count offset clamping and transition guards (
lines 236, 479-492) ignoreEXPENSE_REPORT(reportCount):getSearchRequestOffsetForMissingAllMatchingCount,didJustFinishAllMatchingTotalsRequest, anddidEnableAllMatchingTotalsWithExistingCountall checkisExpenseAllMatchingSelectionandsearch.countinstead ofisRequiredAllMatchingTotalMissing(reportCountforEXPENSE_REPORT).
- Every pagination request (
- In
What changes do you think we should make in order to solve the problem?
-
Backend (
Expensify/Auth/ Web-Expensify):- Fix the
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.
- Fix the
-
App-side hardening in
src/components/Search/index.tsxandlines 479-492, 1064:- Unify all-matching totals handling across both
EXPENSEandEXPENSE_REPORTusingisRequiredAllMatchingTotalMissing(typeof searchResults?.search?.reportCount !== 'number'forEXPENSE_REPORT,typeof searchResults?.search?.count !== 'number'forEXPENSE):const isAllMatchingSelectionWithTotals = (type === CONST.SEARCH.DATA_TYPES.EXPENSE || isExpenseReportType) && areAllMatchingItemsSelected; const isRequiredAllMatchingTotalMissing = isExpenseReportType && areAllMatchingItemsSelected ? typeof searchResults?.search?.reportCount !== 'number' : typeof searchResults?.search?.count !== 'number'; const isAllMatchingItemsCountMissing = isAllMatchingSelectionWithTotals && isRequiredAllMatchingTotalMissing; const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals); const shouldCalculateNextPageTotals = useSearchShouldCalculateTotals(currentSearchKey, isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals) && !shouldUseLiveData; - Update
didJustFinishAllMatchingTotalsRequestanddidEnableAllMatchingTotalsWithExistingCount(lines 479-492) to useisAllMatchingSelectionWithTotalsand!isRequiredAllMatchingTotalMissingsoEXPENSE_REPORTalso stops re-requesting totals onoffset > 0oncereportCountandtotalhave been fetched atoffset === 0.
- Unify all-matching totals handling across both
What alternative solutions did you explore? (Optional)
- Summing
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).
Yeah I'll take a look at this
Pinged the contributors to see if they can repro this either
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.
Yeah that was what I saw too, lets see about truph
BTW test it with an account that has a hell lot of expenses
I tested now and still happens for both Expenses and Reports $0.02 total
I am unable to reproduce the bug. The total value looks correct from my side:
https://github.com/user-attachments/assets/3df3132c-cd6d-468f-94d4-0f4f0ac6b131
@FitseTLT are there any other steps that you know of?
Nope @JS00001 I think the best way to debug I suggest is to investigate on my account [email protected] if possible.
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Reports (and Spend > Expenses) on an account with multiple pages of expenses, when filtering by total:>0 and clicking Select all (selecting all matching items across pages), the selected total in the footer drops to an incorrect near-zero value ($0.02), which is even lower than the sum displayed when only selecting the items on the current page.
What is the root cause of that problem?
There are two causes—one in how src/components/Search/index.tsx requests shouldCalculateTotals across pages and data types, and one in how the backend/footer handles searchResults.search.total:
-
src/components/Search/index.tsx(lines 239-254,499-516,1063-1065) re-requestsshouldCalculateTotals: trueonoffset > 0pages and treatsEXPENSE_REPORTasymmetrically fromEXPENSE:const isExpenseAllMatchingSelection = type === CONST.SEARCH.DATA_TYPES.EXPENSE && areAllMatchingItemsSelected; const isAllMatchingItemsCountMissing = isExpenseAllMatchingSelection && typeof searchResults?.search?.count !== 'number'; const shouldCalculateExpenseTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isExpenseAllMatchingSelection); const shouldCalculateTotals = (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. const shouldCalculateNextPageTotals = shouldCalculateTotals && !shouldUseLiveData;- Notice the comment at line 243: "A response with totals restarts the counted reports, so a later page would drop page 1's."
- However, because
isExpenseAllMatchingSelection(line 239) only checkstype === CONST.SEARCH.DATA_TYPES.EXPENSE:- When
typeisCONST.SEARCH.DATA_TYPES.EXPENSE_REPORT(Spend > Reports) andareAllMatchingItemsSelectedistrue,(areAllMatchingItemsSelected && !isExpenseAllMatchingSelection)evaluates totruefor everyoffset(not justoffset === 0). Every subsequent pagination request (offset > 0) sendsshouldCalculateTotals: true, overwriting the snapshot'ssearch.totalwith the tail-page total! - Even on Spend > Expenses (
type === CONST.SEARCH.DATA_TYPES.EXPENSE), when the user is on page 1 (offset === 0) with Select all active and scrolls to load page 2 (nextOffset = 50),fetchMoreResults(line 1064) passesshouldCalculateTotals: shouldCalculateNextPageTotalswhileoffsetin the render closure is still0! Consequently, theoffset: 50(or last-page) request is sent withshouldCalculateTotals: true, overwritingsearchResults.search.totalwith the sum of only the remaining items at the end of the result set (e.g.,$0.02)! - Likewise,
getSearchRequestOffsetForMissingAllMatchingCount(line 246),didJustFinishAllMatchingTotalsRequest(lines 502-507), anddidEnableAllMatchingTotalsWithExistingCount(lines 511-513) all checkisExpenseAllMatchingSelectionandsearchResults?.search?.countinstead of also coveringisExpenseReportType(reportCount).
- When
-
Backend
Searchaggregate ontotal:>0:- When
areAllMatchingItemsSelectedistrueandexcludedTransactionsis empty,SearchSelectionFooter.tsx(lines 812-816) displaysmetadataTotal - excludedTotal(searchResults.search.total) directly, whereas Select all on this page (areAllMatchingItemsSelected === false) sums the loaded rows on the client (shouldUseClientTotal = trueatSearchSelectionFooter.tsx:442, 752-766).
- When
What changes do you think we should make in order to solve the problem?
-
In
src/components/Search/index.tsx(lines 239-254,502-515,1060-1068):- Unify all-matching totals calculation across both
EXPENSEandEXPENSE_REPORTso that:shouldCalculateTotalsis only requested atoffset === 0(or whenisRequiredAllMatchingTotalMissingistrue, clampingsearchRequestOffsetto0viagetSearchRequestOffsetForMissingAllMatchingCount).- Pagination requests in
fetchMoreResults(nextOffset > 0) never sendshouldCalculateTotals: trueunless the all-matching count/total is missing (in which case offset is clamped to0), preventing later pages from overwriting page 1'ssearch.total:
const isAllMatchingSelectionWithTotals = (type === CONST.SEARCH.DATA_TYPES.EXPENSE || isExpenseReportType) && areAllMatchingItemsSelected; const isRequiredAllMatchingTotalMissing = isExpenseReportType && areAllMatchingItemsSelected ? typeof searchResults?.search?.reportCount !== 'number' : typeof searchResults?.search?.count !== 'number'; const isAllMatchingItemsCountMissing = isAllMatchingSelectionWithTotals && isRequiredAllMatchingTotalMissing; const shouldCalculateTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals); const shouldCalculateNextPageTotals = useSearchShouldCalculateTotals(currentSearchKey, isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals) && !shouldUseLiveData; const previousShouldCalculateTotals = usePrevious(shouldCalculateTotals); const searchRequestOffset = getSearchRequestOffsetForMissingAllMatchingCount(offset, searchResults?.search?.offset, isAllMatchingItemsCountMissing);- Update
didJustFinishAllMatchingTotalsRequestanddidEnableAllMatchingTotalsWithExistingCount(lines 502-515) to useisAllMatchingSelectionWithTotalsand!isRequiredAllMatchingTotalMissing.
- Unify all-matching totals calculation across both
-
Backend (
Expensify/Auth/Web-Expensify):- If the
offset: 0Searchresponse on[email protected]already returnssearch.total = 2fortotal:>0, ensure the backend totals query applies thetotal > 0filter with the same sign/level convention as the row query.
- If the
What alternative solutions did you explore? (Optional)
- Computing the select-all total purely on the client from
selectedTransactions: rejected becauseselectedTransactionsonly holds transactions from pages that have already been fetched into the client snapshot, not across unloaded pages. FixingshouldCalculateTotals/shouldCalculateNextPageTotalsandsearchRequestOffsetinSearch/index.tsxensures totals are always fetched atoffset: 0and never overwritten byoffset > 0pagination requests.
Proposal
Please re-state the problem that we are trying to solve in this issue.
When filtering by total:>0 on Spend > Reports (type:expense-report) or Spend > Expenses (type:expense) on an account with multiple pages of expenses, selecting all items on the current page displays the expected positive sum (computed client-side from the loaded rows), whereas selecting all matching items across all pages displays an incorrect near-zero sum ($0.02).
What is the root cause of that problem?
When switching from a page-only selection (hasPartialSelection === true) to Select all (areAllMatchingItemsSelected === true, excludedTransactions === {}), SearchSelectionFooter.tsx:404, 777 switches from summing loaded rows on the client (shouldUseClientTotal = true) to displaying the snapshot's metadataTotal (searchResults?.search?.total).
There are two coupled defects that cause searchResults.search.total to resolve to $0.02 (2 cents):
-
Client-side pagination and offset handling in
src/components/Search/index.tsx,src/hooks/useSearchShouldCalculateTotals.ts, andsrc/components/Search/SearchSelectionFooter.tsxsendsshouldCalculateTotals: truewithoffset > 0, overwriting the snapshot'ssearch.total:- Asymmetric
isExpenseAllMatchingSelectioninsrc/components/Search/index.tsx:237-243:
Becauseconst isExpenseAllMatchingSelection = type === CONST.SEARCH.DATA_TYPES.EXPENSE && areAllMatchingItemsSelected; const isAllMatchingItemsCountMissing = isExpenseAllMatchingSelection && typeof searchResults?.search?.count !== 'number'; const shouldCalculateExpenseTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isExpenseAllMatchingSelection); const shouldCalculateTotals = (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. const shouldCalculateNextPageTotals = shouldCalculateTotals && !shouldUseLiveData;isExpenseAllMatchingSelectiononly checkstype === CONST.SEARCH.DATA_TYPES.EXPENSE, on Spend > Reports (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT)(areAllMatchingItemsSelected && !isExpenseAllMatchingSelection)istrueat everyoffset, so every pagination request (offset > 0) sendsshouldCalculateTotals: trueand overwritessearchResults.search.total. - First pagination step (
0 -> 50) infetchMoreResults(src/components/Search/index.tsx:1103-1111) sendsshouldCalculateTotals: trueeven onSpend > Expenses: Whenoffsetis0andareAllMatchingItemsSelectedistrue,shouldCalculateTotalsandshouldCalculateNextPageTotalsare bothtruein the current render closure. WhenfetchMoreResultsfires fornextOffset = 50, it callshandleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals })using that closure'struevalue, sendingoffset: 50withshouldCalculateTotals: true. getSearchRequestOffsetForMissingAllMatchingCount(src/hooks/useSearchShouldCalculateTotals.ts:9-14) does not clamp to0when the user has already paginated (offset === serverOffset > 0):
If the user scrolls to a later page (function getSearchRequestOffsetForMissingAllMatchingCount(offset: number, serverOffset: number | undefined, isAllMatchingItemsCountMissing: boolean): number { if (!isAllMatchingItemsCountMissing) { return offset; } return Math.min(offset, serverOffset ?? offset); }offset = 50,serverOffset = 50) before clicking Select all,Math.min(50, 50)returns50instead of0, so the totals request is sent atoffset: 50. Similarly,SearchSelectionFooter.tsx:657, 680passesoffset: metadata?.offset ?? 0instead of0when requesting a breakdown total.
- Asymmetric
-
Sign/filter mismatch in the backend
Searchtotals aggregation fortotal:>0:- In Expensify's data model, standard expenses and expense reports store spend as negative integer cents (as reflected in
SearchSelectionFooter.tsx:124-131: "Sources are expense-signed (the negation of the displayed amount), so callers sum them withtotal - source"). getUpdatedFilterValue(src/libs/SearchQueryUtils.ts:885-898) serializestotal:>0asoperator: "gt", value: "0"without sign inversion. When the backendSearchcommand's totals aggregation appliestotal > 0atoffset: 0without the same sign normalization used by the row filter, only positive-signed/netted entries (2cents =$0.02) are included insearch.total.
- In Expensify's data model, standard expenses and expense reports store spend as negative integer cents (as reflected in
What changes do you think we should make in order to solve the problem?
-
Unify all-matching totals eligibility and next-page suppression in
src/components/Search/index.tsxandlines 500-513:- Cover both
EXPENSEandEXPENSE_REPORTunder all-matching totals gating, usingisRequiredAllMatchingTotalMissing(typeof searchResults?.search?.reportCount !== 'number'forEXPENSE_REPORT,typeof searchResults?.search?.count !== 'number'forEXPENSE), and ensureshouldCalculateNextPageTotalsisfalsefornextOffset > 0once the all-matching count/total is present:const isAllMatchingSelectionWithTotals = (type === CONST.SEARCH.DATA_TYPES.EXPENSE || isExpenseReportType) && areAllMatchingItemsSelected; const isRequiredAllMatchingTotalMissing = isExpenseReportType && areAllMatchingItemsSelected ? typeof searchResults?.search?.reportCount !== 'number' : typeof searchResults?.search?.count !== 'number'; const isAllMatchingItemsCountMissing = isAllMatchingSelectionWithTotals && isRequiredAllMatchingTotalMissing; const shouldCalculateExpenseTotals = useSearchShouldCalculateTotals(currentSearchKey, offset === 0 || isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals); const shouldCalculateTotals = (areAllMatchingItemsSelected && !isAllMatchingSelectionWithTotals) || shouldCalculateExpenseTotals; const shouldCalculateNextPageTotals = useSearchShouldCalculateTotals(currentSearchKey, isAllMatchingItemsCountMissing, isAllMatchingSelectionWithTotals) && !shouldUseLiveData; - Update
didJustFinishAllMatchingTotalsRequestanddidEnableAllMatchingTotalsWithExistingCount(lines 500-513) to checkisAllMatchingSelectionWithTotalsand!isRequiredAllMatchingTotalMissing.
- Cover both
-
Ensure missing all-matching totals and footer breakdown totals are requested at
offset: 0:- In
src/components/Search/SearchSelectionFooter.tsx:657, 680, useoffset: 0whenshouldCalculateTotals: trueis requested for the whole-search breakdown total.
- In
-
Backend (
Expensify/Auth/Web-Expensify):- Ensure the
Searchtotals aggregation query applies thetotalfilter (total:>0) with the exact same sign convention and predicate as the row-fetching query sosearch.totalatoffset: 0sums the same matching set of reports/expenses.
- Ensure the
What alternative solutions did you explore? (Optional)
- Computing the select-all total on the client from
selectedTransactions: Rejected becauseselectedTransactionsonly holds items from the pages currently loaded in the client snapshot (e.g., 50 items on page 1), so a multi-page select-all must rely on the server-computedsearch.totalfetched atoffset: 0and protected from being overwritten byoffset > 0pagination requests.
We merged the FE PR because nobody could repro, I'll keep looking into this
@Ollyws Whoops! This issue is 2 days overdue. Let's get this updated quick!
Contributor details Your Expensify account email: [email protected] Upwork Profile Link: https://www.upwork.com/freelancers/~016c1aa34b51059d42
Proposal
Please re-state the problem that we are trying to solve in this issue.
In Spend > Reports (and Spend > Expenses) on accounts with multiple pages of records, when filtering on total:>0 and clicking Select all (selecting all records across pages), the selected total in the footer displays an incorrect near-zero amount ($0.02), even though selecting all rows on the current page displays the correct positive sum.
What is the root cause of that problem?
In src/components/Search/SearchSelectionFooter.tsx:
- When selecting all items across pages (
areAllSelected), the footer transitions from calculating totals client-side from loaded rows to requesting whole-search converted totals viagetFooterConvertedAmounts:// SearchSelectionFooter.tsx:578-586 if (!wasSearchTotalRequested) { getFooterConvertedAmounts({ queryJSON: currentSearchQueryJSON, searchKey: currentSearchKey, targetCurrency: selectedCurrency, sources: metadataTotal !== undefined ? {searchTotals: {[currentSearchHash]: {[selectedCurrency]: metadataTotal}}} : undefined, }); } - When the filter
total:>0is applied:- For individual rows loaded in the client window,
row.totalis evaluated positive. - However, in
searchTotalsMetadatareturned by the search endpoint (or derived bymetadataTotal),total:>0is interpreted without accounting for the signed sign convention of expense reports (where expense report totals are stored negative in the database, e.g.-15000cents). - In
getFooterConvertedAmounts,metadataTotalreceives the un-negated raw aggregate or zero-floor aggregate from the backend response when filteringtotal:>0vs expense amounts, returning a normalized nominal residue (0.02).
- For individual rows loaded in the client window,
- Furthermore, when
selectedCurrencyConvertedTotalis updated,SearchSelectionFooterfalls back toconvertedSearchTotal?.[selectedCurrency]instead of computing the sum from the client-cachedsearchTotalsMetadata.totalor reconciling the sign convention.
What changes do you think we should make in order to solve the problem?
- In
src/components/Search/SearchSelectionFooter.tsx: Ensure that whenareAllSelectedis true andmetadataTotalis available fromsearchResults.searchTotalsMetadata:- If
currentSearchKeyis an expense report or expense search, verify thatmetadataTotalrespects the absolute/negated total value for expense reports before passing it togetFooterConvertedAmounts. - In
selectedTotal:
const selectedTotal = useMemo(() => { if (areAllSelected) { if (convertedSearchTotal?.[selectedCurrency] !== undefined && convertedSearchTotal[selectedCurrency] > 0) { return convertedSearchTotal[selectedCurrency]; } // Fallback to absolute aggregate of loaded items if backend search total is near zero/invalid return Math.abs(currentSearchMetadataTotal ?? 0); } return computedSelectedTotal; }, [...]); - If
- In
src/libs/actions/Search.ts(getFooterConvertedAmounts): Ensuresources.searchTotalssanitizes the query total to match the filter semantics (total:>0), avoiding passing conflicting signs in the conversion payload.
Tests
- Log in with an account having multiple pages of expenses.
- Go to Spend > Reports.
- Apply filter
total:>0. - Click "Select all" (across all pages).
- Verify that the displayed total in the footer accurately reflects the positive sum of all filtered expenses.
- Deselect one item and verify the total adjusts accordingly.
- [x] Verify that no errors appear in the JS console
QA Steps
- Navigate to Spend > Reports on Web.
- Search with filter
total:>0. - Click "Select all".
- Confirm the selected total is positive and matches the filtered dataset sum.
✅ Contributor details stored successfully. Thank you for contributing to Expensify!