App icon indicating copy to clipboard operation
App copied to clipboard

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

Open m-natarajan opened this issue 1 month ago • 36 comments

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
  • [x] Windows: Chrome
  • [x] MacOS: Chrome / Safari

Screenshots/Videos

https://github.com/user-attachments/assets/7a5d851c-bcda-4b81-9c88-2ada2b24db73

View all open jobs on GitHub

Upwork Automation - Do Not Edit

m-natarajan avatar Oct 26 '26 11:10 m-natarajan

cc @JS00001 most probably a BE bug

FitseTLT avatar Oct 26 '26 12:10 FitseTLT

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

MelvinBot avatar Oct 26 '26 12:10 MelvinBot

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

melvin-bot[bot] avatar Oct 26 '26 12:10 melvin-bot[bot]

Job added to Upwork: https://www.upwork.com/jobs/~022114689088128858232

melvin-bot[bot] avatar Oct 26 '26 12:10 melvin-bot[bot]

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

shilo1979jk avatar Oct 26 '26 12:10 shilo1979jk

Yeah I'll take a look at this

JS00001 avatar Oct 26 '26 18:10 JS00001

Pinged the contributors to see if they can repro this either

JS00001 avatar Oct 27 '26 13:10 JS00001

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.

mkhutornyi avatar Oct 27 '26 13:10 mkhutornyi

Yeah that was what I saw too, lets see about truph

JS00001 avatar Oct 27 '26 13:10 JS00001

BTW test it with an account that has a hell lot of expenses

FitseTLT avatar Oct 27 '26 13:10 FitseTLT

I tested now and still happens for both Expenses and Reports $0.02 total

FitseTLT avatar Oct 27 '26 13:10 FitseTLT

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

truph01 avatar Oct 28 '26 02:10 truph01

@FitseTLT are there any other steps that you know of?

JS00001 avatar Oct 28 '26 11:10 JS00001

Nope @JS00001 I think the best way to debug I suggest is to investigate on my account [email protected] if possible.

FitseTLT avatar Oct 28 '26 12:10 FitseTLT

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:

  1. src/components/Search/index.tsx (lines 239-254, 499-516, 1063-1065) re-requests shouldCalculateTotals: true on offset > 0 pages and treats EXPENSE_REPORT asymmetrically from EXPENSE:

    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 checks type === CONST.SEARCH.DATA_TYPES.EXPENSE:
      1. When type is CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT (Spend > Reports) and areAllMatchingItemsSelected is true, (areAllMatchingItemsSelected && !isExpenseAllMatchingSelection) evaluates to true for every offset (not just offset === 0). Every subsequent pagination request (offset > 0) sends shouldCalculateTotals: true, overwriting the snapshot's search.total with the tail-page total!
      2. 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) passes shouldCalculateTotals: shouldCalculateNextPageTotals while offset in the render closure is still 0! Consequently, the offset: 50 (or last-page) request is sent with shouldCalculateTotals: true, overwriting searchResults.search.total with the sum of only the remaining items at the end of the result set (e.g., $0.02)!
      3. Likewise, getSearchRequestOffsetForMissingAllMatchingCount (line 246), didJustFinishAllMatchingTotalsRequest (lines 502-507), and didEnableAllMatchingTotalsWithExistingCount (lines 511-513) all check isExpenseAllMatchingSelection and searchResults?.search?.count instead of also covering isExpenseReportType (reportCount).
  2. Backend Search aggregate on total:>0:

    • When areAllMatchingItemsSelected is true and excludedTransactions is empty, SearchSelectionFooter.tsx (lines 812-816) displays metadataTotal - excludedTotal (searchResults.search.total) directly, whereas Select all on this page (areAllMatchingItemsSelected === false) sums the loaded rows on the client (shouldUseClientTotal = true at SearchSelectionFooter.tsx:442, 752-766).

What changes do you think we should make in order to solve the problem?

  1. In src/components/Search/index.tsx (lines 239-254, 502-515, 1060-1068):

    • Unify all-matching totals calculation across both EXPENSE and EXPENSE_REPORT so that:
      • shouldCalculateTotals is only requested at offset === 0 (or when isRequiredAllMatchingTotalMissing is true, clamping searchRequestOffset to 0 via getSearchRequestOffsetForMissingAllMatchingCount).
      • Pagination requests in fetchMoreResults (nextOffset > 0) never send shouldCalculateTotals: true unless the all-matching count/total is missing (in which case offset is clamped to 0), preventing later pages from overwriting page 1's search.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 didJustFinishAllMatchingTotalsRequest and didEnableAllMatchingTotalsWithExistingCount (lines 502-515) to use isAllMatchingSelectionWithTotals and !isRequiredAllMatchingTotalMissing.
  2. Backend (Expensify/Auth / Web-Expensify):

    • If the offset: 0 Search response on [email protected] already returns search.total = 2 for total:>0, ensure the backend totals query applies the total > 0 filter with the same sign/level convention as the row query.

What alternative solutions did you explore? (Optional)

  • Computing the select-all total purely on the client from selectedTransactions: rejected because selectedTransactions only holds transactions from pages that have already been fetched into the client snapshot, not across unloaded pages. Fixing shouldCalculateTotals / shouldCalculateNextPageTotals and searchRequestOffset in Search/index.tsx ensures totals are always fetched at offset: 0 and never overwritten by offset > 0 pagination requests.

Enes2553 avatar Oct 28 '26 17:10 Enes2553

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

  1. Client-side pagination and offset handling in src/components/Search/index.tsx, src/hooks/useSearchShouldCalculateTotals.ts, and src/components/Search/SearchSelectionFooter.tsx sends shouldCalculateTotals: true with offset > 0, overwriting the snapshot's search.total:

    • Asymmetric isExpenseAllMatchingSelection in src/components/Search/index.tsx:237-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;
      // 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;
      
      Because isExpenseAllMatchingSelection only checks type === CONST.SEARCH.DATA_TYPES.EXPENSE, on Spend > Reports (type === CONST.SEARCH.DATA_TYPES.EXPENSE_REPORT) (areAllMatchingItemsSelected && !isExpenseAllMatchingSelection) is true at every offset, so every pagination request (offset > 0) sends shouldCalculateTotals: true and overwrites searchResults.search.total.
    • First pagination step (0 -> 50) in fetchMoreResults (src/components/Search/index.tsx:1103-1111) sends shouldCalculateTotals: true even on Spend > Expenses: When offset is 0 and areAllMatchingItemsSelected is true, shouldCalculateTotals and shouldCalculateNextPageTotals are both true in the current render closure. When fetchMoreResults fires for nextOffset = 50, it calls handleSearch({ ..., offset: nextOffset, shouldCalculateTotals: shouldCalculateNextPageTotals }) using that closure's true value, sending offset: 50 with shouldCalculateTotals: true.
    • getSearchRequestOffsetForMissingAllMatchingCount (src/hooks/useSearchShouldCalculateTotals.ts:9-14) does not clamp to 0 when the user has already paginated (offset === serverOffset > 0):
      function getSearchRequestOffsetForMissingAllMatchingCount(offset: number, serverOffset: number | undefined, isAllMatchingItemsCountMissing: boolean): number {
          if (!isAllMatchingItemsCountMissing) {
              return offset;
          }
          return Math.min(offset, serverOffset ?? offset);
      }
      
      If the user scrolls to a later page (offset = 50, serverOffset = 50) before clicking Select all, Math.min(50, 50) returns 50 instead of 0, so the totals request is sent at offset: 50. Similarly, SearchSelectionFooter.tsx:657, 680 passes offset: metadata?.offset ?? 0 instead of 0 when requesting a breakdown total.
  2. Sign/filter mismatch in the backend Search totals aggregation for total:>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 with total - source").
    • getUpdatedFilterValue (src/libs/SearchQueryUtils.ts:885-898) serializes total:>0 as operator: "gt", value: "0" without sign inversion. When the backend Search command's totals aggregation applies total > 0 at offset: 0 without the same sign normalization used by the row filter, only positive-signed/netted entries (2 cents = $0.02) are included in search.total.

What changes do you think we should make in order to solve the problem?

  1. Unify all-matching totals eligibility and next-page suppression in src/components/Search/index.tsx and lines 500-513:

    • Cover both EXPENSE and EXPENSE_REPORT under all-matching totals gating, using isRequiredAllMatchingTotalMissing (typeof searchResults?.search?.reportCount !== 'number' for EXPENSE_REPORT, typeof searchResults?.search?.count !== 'number' for EXPENSE), and ensure shouldCalculateNextPageTotals is false for nextOffset > 0 once 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 didJustFinishAllMatchingTotalsRequest and didEnableAllMatchingTotalsWithExistingCount (lines 500-513) to check isAllMatchingSelectionWithTotals and !isRequiredAllMatchingTotalMissing.
  2. Ensure missing all-matching totals and footer breakdown totals are requested at offset: 0:

  3. Backend (Expensify/Auth / Web-Expensify):

    • Ensure the Search totals aggregation query applies the total filter (total:>0) with the exact same sign convention and predicate as the row-fetching query so search.total at offset: 0 sums the same matching set of reports/expenses.

What alternative solutions did you explore? (Optional)

  • Computing the select-all total on the client from selectedTransactions: Rejected because selectedTransactions only 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-computed search.total fetched at offset: 0 and protected from being overwritten by offset > 0 pagination requests.

dhaulagani avatar Oct 28 '26 22:10 dhaulagani

We merged the FE PR because nobody could repro, I'll keep looking into this

JS00001 avatar Oct 29 '26 18:10 JS00001

@Ollyws Whoops! This issue is 2 days overdue. Let's get this updated quick!

melvin-bot[bot] avatar Oct 29 '26 21:10 melvin-bot[bot]

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:

  1. When selecting all items across pages (areAllSelected), the footer transitions from calculating totals client-side from loaded rows to requesting whole-search converted totals via getFooterConvertedAmounts:
    // SearchSelectionFooter.tsx:578-586
    if (!wasSearchTotalRequested) {
        getFooterConvertedAmounts({
            queryJSON: currentSearchQueryJSON,
            searchKey: currentSearchKey,
            targetCurrency: selectedCurrency,
            sources: metadataTotal !== undefined ? {searchTotals: {[currentSearchHash]: {[selectedCurrency]: metadataTotal}}} : undefined,
        });
    }
    
  2. When the filter total:>0 is applied:
    • For individual rows loaded in the client window, row.total is evaluated positive.
    • However, in searchTotalsMetadata returned by the search endpoint (or derived by metadataTotal), total:>0 is interpreted without accounting for the signed sign convention of expense reports (where expense report totals are stored negative in the database, e.g. -15000 cents).
    • In getFooterConvertedAmounts, metadataTotal receives the un-negated raw aggregate or zero-floor aggregate from the backend response when filtering total:>0 vs expense amounts, returning a normalized nominal residue (0.02).
  3. Furthermore, when selectedCurrencyConvertedTotal is updated, SearchSelectionFooter falls back to convertedSearchTotal?.[selectedCurrency] instead of computing the sum from the client-cached searchTotalsMetadata.total or reconciling the sign convention.

What changes do you think we should make in order to solve the problem?

  1. In src/components/Search/SearchSelectionFooter.tsx: Ensure that when areAllSelected is true and metadataTotal is available from searchResults.searchTotalsMetadata:
    • If currentSearchKey is an expense report or expense search, verify that metadataTotal respects the absolute/negated total value for expense reports before passing it to getFooterConvertedAmounts.
    • 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;
    }, [...]);
    
  2. In src/libs/actions/Search.ts (getFooterConvertedAmounts): Ensure sources.searchTotals sanitizes the query total to match the filter semantics (total:>0), avoiding passing conflicting signs in the conversion payload.

Tests

  1. Log in with an account having multiple pages of expenses.
  2. Go to Spend > Reports.
  3. Apply filter total:>0.
  4. Click "Select all" (across all pages).
  5. Verify that the displayed total in the footer accurately reflects the positive sum of all filtered expenses.
  6. Deselect one item and verify the total adjusts accordingly.
  • [x] Verify that no errors appear in the JS console

QA Steps

  1. Navigate to Spend > Reports on Web.
  2. Search with filter total:>0.
  3. Click "Select all".
  4. Confirm the selected total is positive and matches the filtered dataset sum.

bhomvratrai-glitch avatar Nov 01 '26 13:11 bhomvratrai-glitch

✅ Contributor details stored successfully. Thank you for contributing to Expensify!

melvin-bot[bot] avatar Nov 01 '26 13:11 melvin-bot[bot]