calc is sorting incorrectly

sorting works on pure number cells (ctrl+f8 in blue) however in cells formated as number but the value is coming from a formula they show as green in ctrl+f8 and are sorted in some weird way.

i have no idea why this happens and how to fix it, they are just numbers.

some cells had an invalid number coming out of the formula, and once i fixed that the sorting is working.

the cell had a X+Y+Z+A+B type of formula, that doesnt work properly when some of those cells have text and not a number, and once i changed to a SUM type of formula, that ignores the text and returns a proper value, even if 0, and then sorting works