TaxGuyBill
Level 15

The program is doing it it correctly.  Capital gains lower the 'taxable income' threshold.

The deduction is the LOWER of (a) 20% of QBI or (b) 20% of 'taxable income' (after subtracting capital gains).

As for the reasoning behind it, that is how Congress wrote the law.  See §199A(a).

https://www.law.cornell.edu/uscode/text/26/199A

 

View solution in original post