Forum Discussion
Understanding DAX operator overloading
Hi,
I've read that DAX supports the operator overloading.
Operator overloading in computer programming is the process of defining custom behaviors for operators like +, -.
So, a same operator could be overloaded to work with an integer and a string.
But how does DAX support the operator overloading? Does the operator result depend on the operator data type or the data type of the operands?
I'd like to understand better the DAX operator overloading.
Thanks
9 Replies
- lbendlinSuper User
For example: TODAY()+1
for date math
Or: {1}
for table math
Or: CONCATENATEX(table,[column])
for table to scalar math
- Ritaf1983Super User
Hi pmscorca
DAX doesn't support operator overloading in the traditional object-oriented sense, but it does define different behaviors for the same operator based on the operand types.
For example, + / - works for numberical data types and also for adding days to a date.
However, DAX doesn't use + for strings – it uses & for string concatenation.If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
- pmscorcaKudo Kingpin
Ok, but does the operator result depend on the operator data type (or better the expected data type of the operands) or the real data type of the operands?
The + operator expects numeric operands; if numeric strings are used, this operator continues to return a numeric result.
The & operator expects alphanumeric operands; if numeric strings are used, this operator raises an error.
It seems that it drives the expected operand data type without overriding the operator behaviour, isn't it?
- Ritaf1983Super User
Hi pmscorca
It also depends on what’s on the other side of the operator.
For example, if you try to use the+operator between a number and a text string, you'll get an error.
But if the number is actually stored as text, and you try to concatenate it with another string, the engine treats both operands as text and performs concatenation.
So the operator behavior depends not only on the expected data type but also on the actual data types involved – and sometimes the result is determined by how the engine coerces types based on context.If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Hi pmscorca,
Thank you for reaching out in Microsoft Community Forum.
Thank you lbendlin, Ritaf1983 for the helpful response.
As suggested by Ibendlin and Ritaf1983, I hope this information was helpful. Please let me know if you have any further questions or you'd like to discuss this further. If this answers your question, please "Accept as Solution" and give it a 'Kudos' so others can find it easily.
Please continue using Microsoft community forum.
Regards,
Pavan. - AnonymousNot applicable
Hi pmscorca,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please "Accept as Solution" and give a 'Kudos' so other members can easily find it.
Thank you,
Pavan. - AnonymousNot applicable
Hi pmscorca,
I wanted to follow up since we haven't heard back from you regarding our last response. We hope your issue has been resolved.
If the community member's answer your query, please mark it as "Accept as Solution" and select "Yes" if it was helpful.
If you need any further assistance, feel free to reach out.
Please continue using Microsoft community forum.
Thank you,
Pavan.