Targeted therapies based on underlying tumor genomic susceptible alterations have been approved for patients with metastatic prostate cancer (mPC) and advanced urothelial carcinoma (aUC). To assess trends and disparities in next-generation sequencing (NGS) testing among patients with mPC and aUC. This retrospective cohort study used an electronic health record-derived database to extract deidentified data of patients receiving care from US physician practices, hospital-affiliated clinics, and academic practices. Patients diagnosed with mPC or aUC between March 1, 2015, and December 31, 2022, were included. Social determinants of health evaluated by race and ethnicity, socioeconomic status (SES), region, insurance type, and sex (for aUC). The primary outcomes were (1) NGS testing rate by year of mPC and aUC diagnosis using Clopper-Pearson 2-sided 95% CIs and (2) time to NGS testing, which considered death as a competing risk. Cumulative incidence functions were estimated for time to NGS testing. Disparities in subdistributional incidence of NGS testing were assessed by race and ethnicity, SES, region, insurance type, and sex (for aUC) using the Fine-Gray modified Cox proportional hazards model, assuming different subdistribution baseline hazards by year of mPC and aUC diagnosis. A total of 11 927 male patients with mPC (167 Asian [1.6%], 1236 Black [11.6%], 687 Hispanic or Latino [6.4%], 7037 White [66.0%], and 1535 other [14.4%] among 10 662 with known race and ethnicity) and 6490 patients with aUC (4765 male [73.4%]; 80 Asian [1.4%], 283 Black [4.8%], 257 Hispanic or Latino [4.4%], 4376 White [74.9%], and 845 other [14.5%] among 5841 with known race and ethnicity) were eligible and included. Both cohorts had a median age of 73 years (IQR, 66-80 years), and most underwent NGS testing before first-line treatment in the mPC cohort (1502 [43.0%]) and before second-line treatment in the aUC cohort (1067 [51.3%]). In the mPC cohort, the rates of NGS testing increased from 19.0% in 2015 to 27.1% in 2022, but Black patients (hazard ratio [HR], 0.75; 95% CI, 0.67-0.84) and Hispanic or Latino patients (HR, 0.70; 95% CI, 0.60-0.82) were less likely to undergo NGS testing. Patients with mPC who had low SES (quintile 1: HR, 0.74 [95% CI, 0.66-0.83]; quintile 2: HR, 0.89 [95% CI, 0.80-0.99]), had Medicaid (HR, 0.53; 95% CI, 0.38-0.74) or Medicare or other government insurance (HR, 0.89; 95% CI, 0.82-0.98), or lived in the West (HR, 0.81; 95% CI, 0.70-0.94) also were less likely to undergo testing. In the aUC cohort, the NGS rate increased from 14.1% in 2015 to 46.6% in 2022, but Black patients (HR, 0.76; 95% CI, 0.61-0.96) and those with low SES (quintile 1: HR 0.77 [95% CI, 0.66-0.89]; quintile 2: HR, 0.87 [95% CI, 0.76-1.00]) or Medicaid (HR, 0.72; 95% CI, 0.53-0.97) or Medicare or other government insurance (HR, 0.88; 95% CI, 0.78-0.99) were less likely to undergo NGS testing. Patients with aUC living in the South were more likely to undergo testing (HR, 1.29; 95% CI, 1.12-1.49). These findings suggest that although NGS tumor testing rates improved over time, the majority of patients still did not undergo testing. These data may help with understanding current disparities associated with NGS testing and improving access to standard-of-care health care services.