Skip to main content

Calculate the weighted average of subform data by formula

1. Usage scenarios​

In this example, we will learn how to calculate the weighted average of eligible data in a subform by formula.

2. Implement functions​

2.1. Configuration page​

Selected: The radio component.

Quantity: numeric component

Price: numeric component (decimal places: 2)

Volume sum: numeric component (decimal places: 2)

Quantity and: numeric components

Average price: numeric component (decimal places: 2)

2.2. Configure field formulas​

Volume sum (calculation condition: Selected = yes):

{"text":"SUM(IF(EQ(​子表单.是否选中​,\"是\"),​子表单.量​*​子表单.价​,0))","marks":[{"from":{"line":0,"ch":10,"sticky":null},"to":{"line":0,"ch":20,"sticky":null},"value":"radioField_lw5pla9v","invalid":false},{"from":{"line":0,"ch":26,"sticky":null},"to":{"line":0,"ch":33,"sticky":null},"value":"numberField_lw5pla9w","invalid":false},{"from":{"line":0,"ch":34,"sticky":null},"to":{"line":0,"ch":41,"sticky":null},"value":"numberField_lw5pla9x","invalid":false}],"isCmData":true}

Quantity sum (calculation condition: Selected = yes):

{"text":"SUM(IF(EQ(​子表单.是否选中​,\"是\"),​子表单.量​,0))","marks":[{"from":{"line":0,"ch":10,"sticky":null},"to":{"line":0,"ch":20,"sticky":null},"value":"radioField_lw5pla9v","invalid":false},{"from":{"line":0,"ch":26,"sticky":null},"to":{"line":0,"ch":33,"sticky":null},"value":"numberField_lw5pla9w","invalid":false}],"isCmData":true}

Average Price (calculation condition: Selected = yes):

{"text":"SUM(IF(EQ(​子表单.是否选中​,\"是\"),​子表单.量​*​子表单.价​,0))/SUM(IF(EQ(​子表单.是否选中​,\"是\"),​子表单.量​,0))","marks":[{"from":{"line":0,"ch":10,"sticky":null},"to":{"line":0,"ch":20,"sticky":null},"value":"radioField_lw5pla9v","invalid":false},{"from":{"line":0,"ch":26,"sticky":null},"to":{"line":0,"ch":33,"sticky":null},"value":"numberField_lw5pla9w","invalid":false},{"from":{"line":0,"ch":34,"sticky":null},"to":{"line":0,"ch":41,"sticky":null},"value":"numberField_lw5pla9x","invalid":false},{"from":{"line":0,"ch":56,"sticky":null},"to":{"line":0,"ch":66,"sticky":null},"value":"radioField_lw5pla9v","invalid":false},{"from":{"line":0,"ch":72,"sticky":null},"to":{"line":0,"ch":79,"sticky":null},"value":"numberField_lw5pla9w","invalid":false}],"isCmData":true}

3. Effect​

4. Try it online​

This doc is generated using machine translation. Any discrepancies or differences created in the translation are not binding and have no legal effect for compliance or enforcement purposes.
© 2014–2025 DingTalk Technology Co., Ltd