Skip to content

[$175] Search - Selected total shows incorrect (near-zero) sum when filtering on total:>0 and selecting all #104993

Open

Description

@m-natarajan

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:

  1. Use an account with a large number of expenses.
  2. Go to Spend > Reports.
  3. Apply the filter total:>0 (to exclude negative totals).
  4. Select all expenses matching the filter.
  5. 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
  • Windows: Chrome
  • MacOS: Chrome / Safari

Screenshots/Videos

2026-10-23.19-41-57.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit

Activity

  1. added
    Daily
    Needs Reproduction
    Bug
    on Oct 26, 2026
  2. FitseTLT commented on Oct 26, 2026

    @FitseTLT
    Contributor

    cc @JS00001 most probably a BE bug

  3. MelvinBot commented on Oct 26, 2026

    @MelvinBot
    Contributor

    ⚠️ 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:

    1. 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.
    2. If only offset>0 responses 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

  4. added
    External
    on Oct 26, 2026
  5. melvin-bot commented on Oct 26, 2026

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @Ollyws (External)

  6. 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
  7. melvin-bot commented on Oct 26, 2026

    @melvin-bot
  8. shilo1979jk commented on Oct 26, 2026

    @shilo1979jk

    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):

    1. 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.
    2. App-side asymmetry in src/components/Search/index.tsx for type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT select-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 isExpenseAllMatchingSelection only checks type === CONST.SEARCH.DATA_TYPES.EXPENSE:
        1. 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.
        2. 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.
        3. 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?

    1. 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.
    2. App-side hardening in src/components/Search/index.tsx and lines 479-492, 1064:

      • 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):
        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 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).
  9. JS00001 commented on Oct 26, 2026

    @JS00001
    Contributor

    Yeah I'll take a look at this

  10. JS00001 commented on Oct 27, 2026

    @JS00001
    Contributor

    Pinged the contributors to see if they can repro this either

  11. mkhutornyi commented on Oct 27, 2026

    @mkhutornyi

    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.

  12. 21 remaining items

  13. jeffrey-graham commented on Nov 7, 2026

    @jeffrey-graham
  14. melvin-bot commented on Nov 7, 2026

    @melvin-bot
  15. samithreddychinni commented on Nov 8, 2026

    @samithreddychinni

    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:

    1. 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.

    2. 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.

    3. 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.

  16. melvin-bot commented on Nov 9, 2026

    @melvin-bot

    @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!

  17. melvin-bot commented on Nov 10, 2026

    @melvin-bot

    @Ollyws Huh... This is 4 days overdue. Who can take care of this?

  18. melvin-bot commented on Nov 12, 2026

    @melvin-bot

    @Ollyws 6 days overdue. This is scarier than being forced to listen to Vogon poetry!

  19. cocvn157 commented on Nov 14, 2026

    @cocvn157

    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 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:

    1. Client-side pagination and EXPENSE_REPORT totals gating in src/components/Search/index.tsx:243-258, lines 514-527, and lines 1112, 1138:

      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;
      • 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.
    2. Backend Search totals aggregation sign mismatch on total:>0:

      • src/libs/SearchQueryUtils.ts:885-898 (getUpdatedFilterValue) serializes total:>0 as operator: "gt", value: "0" without sign inversion.
      • 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?

    1. Unify all-matching totals gating across EXPENSE and EXPENSE_REPORT and prevent offset > 0 pagination requests from recalculating totals in src/components/Search/index.tsx:243-258, 481, 514-527:

      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;
      // 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.
      const shouldCalculateNextPageTotals =
          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'.
    2. Clamp missing all-matching count/total requests to offset: 0 in src/hooks/useSearchShouldCalculateTotals.ts:9-14:

      • When isAllMatchingItemsCountMissing is true, ensure the totals request is anchored so a full-search total is not computed starting from a paginated serverOffset > 0.
    3. 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.
  20. expensify-chore-bot commented on Nov 18, 2026

    @expensify-chore-bot

    @Ollyws 12 days overdue now... This issue's end is nigh!

  21. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot

    @Ollyws this issue is now 4 weeks old, please consider:

    • Finding a contributor to fix the bug
    • Closing the issue if BZ has been unable to add the issue to a VIP or Wave project
    • If you have any questions, don't hesitate to start a discussion in #expensify-open-source

    Thanks!

  22. expensify-chore-bot commented on Nov 23, 2026

    @expensify-chore-bot

    This issue has not been updated in over 14 days. @Ollyws eroding to Weekly issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

BugExternalNeeds ReproductionWeekly

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions