Forum Discussion
SUMX over multiple columns - Is this the optimal syntax?
- 4 years ago
I checked your sample data and found no problem. You built the eligible virtual table with SUMMARIZE() function and then used SUMMARIZECOLUMNS() function to return the table with the fields you need. And you don't need to ADDCOLUMNS(It will preserve the context of the original table) and CALCULATETABLE(You mainly rely on relationships rather than specific conditions to filter in addition to the original table) functions.
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.If not, please feel free to ask me.Best Regards,Community Support Team _ Janey
Hi, mattcarter865
If the result is what you want, there is no need to modify anything.
Usually, First add a 'value' column in summarize function then accumulate it, which is more in line with the writing specification.
Measure =
SUMX ( SUMMARIZE ( 'Table', [Column1], [Column2], "Value", 1 / 12 ), [Value] )
I don't understand why you want to accumulate 1/12. If you can share some sample data and your expected result in the visual, maybe I can give you a different solution.
- mattcarter8654 years ago
Helper I
Thanks. The 1/12 is not the important part. I just need to accumulate a constant value (other than 1).
My original formula does work. My question is more about understanding if I'm doing it the "preferred" way. When looking through options for DAX I find it confusing to determine if I should use SUMMARIZE vs SUMMARIZECOLUMNS vs SUMMARIZE/ADDCOLUMNS vs CALCULATETABLE, etc. Plus in my particular example I need to filter the fact table on a particular value (as I showed in my example). https://dax.do/tM4fkfNewjz98s/
- v-janeyg-msft4 years ago
Community Support
I checked your sample data and found no problem. You built the eligible virtual table with SUMMARIZE() function and then used SUMMARIZECOLUMNS() function to return the table with the fields you need. And you don't need to ADDCOLUMNS(It will preserve the context of the original table) and CALCULATETABLE(You mainly rely on relationships rather than specific conditions to filter in addition to the original table) functions.
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.If not, please feel free to ask me.Best Regards,Community Support Team _ Janey