Hello Zain,
Try below method
in your form D.Click on all material groups filed one by one and choose (selected)
this will enable you to select those fields in your formula as independent fields,
in formula choose change characteristics to find your selected field; then do you formula
when selecting a field √ mark will appear on the field
when doing your formula + mark will appear on the filed
Regards,
Ibrahim