The issue with having too "granular" a breakdown with the rows in the table (if you are using the API) you are stuck with it. For example table B01001 is broken down by age and sex. The "primary" variable is sex. There are male and female totals. But age is the "secondary" variable so there are no rows that give the total for say "Under 5 years." You have to add the Male : Under 5 years and Female : Under 5 years rows.
I have a nice R function that downloads the table "group" and attaches the labels from the metadata. I then have a function that takes linear combinations of rows in a table (columns Est and MoE) The R function is based on the "censusapi" R package
(State of MA FIPS 25)
Est MoE
Male : 30 to 34 years 245596 318
Male : 25 to 29 years 250358 394
Male : 40 to 44 years 208058 2998
Male : 35 to 39 years 224342 3052
Male : 50 to 54 years 235548 361
Male : 45 to 49 years 215042 441
Male : 62 to 64 years 130319 2394
Male : 55 to 59 years 245573 2551
Male : 60 and 61 years 93025 1827
Male : 65 and 66 years 76963 1670
Male : 70 to 74 years 138031 2202
Male : 67 to 69 years 103679 2068
Male : 80 to 84 years 52395 1488
Male : 75 to 79 years 82445 1474
Female 3578678 606
Male : 85 years and over 54306 1625
Female : 5 to 9 years 182121 2636
Female : 10 to 14 years 197419 2634
Female : Under 5 years 174546 323
Female : 15 to 17 years 124120 298
Female : 20 years 50778 1502
Female : 18 and 19 years 108312 396
Female : 22 to 24 years 143258 2017
Female : 21 years 50936 1754
Female : 30 to 34 years 246823 272
Female : 25 to 29 years 247846 458
Female : 40 to 44 years 212330 2952
Female : 35 to 39 years 228666 2951
Female : 45 to 49 years 223825 285
Female : 50 to 54 years 245015 346
Female : 60 and 61 years 96092 2253
Female : 55 to 59 years 254311 3020
Female : 65 and 66 years 84787 1807
Female : 62 to 64 years 144068 2620
Female : 70 to 74 years 163566 2257
Female : 67 to 69 years 115894 2341
Female : 80 to 84 years 72738 2001
Female : 75 to 79 years 106706 2139
Female : 85 years and over 104521 2267
Male 3413174 606
Total 6991852 0
Male : 5 to 9 years 189716 2794
Male : Under 5 years 183397 357
Male : 15 to 17 years 129924 299
Male : 18 and 19 years 104293 383
Male : 10 to 14 years 208481 2761
Male : 21 years 50414 1662
Male : 20 years 49917 1494
Male : 22 to 24 years 141352 2048
>
From these building blocks you can easily write an R function to sum the Male and Female blocks to get the age categories.