Skip to content

[Due for payment 2026-04-01] [Insights] Top categories/merchants insight searches should sort by groupTotal desc #84420

Description

@MelvinBot

Bug Description

The "Top categories" and "Top merchants" default insight search links use suboptimal sort parameters. They currently sort alphabetically by category/merchant name instead of by total spend descending.

Current behavior

  • Top categories search URL contains sortBy:groupCategory sortOrder:asc — sorts alphabetically by category name
  • Top merchants search URL contains sortBy:groupMerchant sortOrder:asc — sorts alphabetically by merchant name

While this doesn't affect the default chart views (bar chart for categories, pie chart for merchants), switching to view:table reveals the data isn't sorted by total spend descending — which is the expected behavior for "Top X" reports.

Expected behavior

Both should use sortBy:groupTotal sortOrder:desc so that when viewed as a table, categories and merchants are ordered from highest to lowest total spend.

Root cause

In src/libs/SearchUIUtils.ts, the createTopSearchMenuItem function uses a GROUP_BY_TO_SORT_COLUMN mapping that maps groupBy:category to sortBy:groupCategory and groupBy:merchant to sortBy:groupMerchant, both with sortOrder:asc. For "Top X" insight searches, these should always sort by groupTotal descending.

Recommended fix

Modify createTopSearchMenuItem in src/libs/SearchUIUtils.ts to always use sortBy:groupTotal sortOrder:desc instead of the alphabetical sorting from GROUP_BY_TO_SORT_COLUMN.

Issue OwnerCurrent Issue Owner: @mallenexpensify

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionDailyKSv2

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions