Hello,
qRules is a package developed by Qdabra which includes various functions (commands) that can be used in InfoPath forms. The links I provided above include a free trial download and documentation for your scenario.
If you did not want to use qRules, then you would need to write your own code for this.
Good luck!