Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mattcarter865
Helper I
Helper I

SUMX over multiple columns - Is this the optimal syntax?

I'm trying to design a measure that sums a constant value for each distinct set of values involving multiple columns in my data model.

 

This is similar to the formula I ended up with.

 

'Sales'[Earned Promotions] =
SUMX (
SUMMARIZE (
FILTER ( Sales, Sales[Quantity] = 1 ),
Promotion[Promotion Code],
'Date'[Calendar Year Month]
),
( 1 / 12 )
)

 

Running sample here

https://dax.do/tM4fkfNewjz98s/

 

The intent is to add 1/12th for each month a promotion is going on but only for sales involving a single quantity. (I work in insurance. This is a contrived example meant to mimic calculation of earned policy years.)

 

My formula works, but I am unsure it is the optimal way to structure it. I tried swapping the order so that SUMMARIZE was called from within FILTER, but performance seemed about the same. 

 

I'm still new to DAX and trying to navigate the overly numerous ways to manipulate tables.

1 ACCEPTED SOLUTION

@mattcarter865 

 

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

 

View solution in original post

5 REPLIES 5
v-janeyg-msft
Community Support
Community Support

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.

 

Best Regards,
Community Support Team _ Janey
 

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/

 

 

@mattcarter865 

 

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

 

amitchandak
Super User
Super User

@mattcarter865 , What filter is ensuring distinct Promotion Code and month combination?

 

I usually prefer to create a table in such a case

 

addcolumns (
SUMMARIZE (
FILTER ( Sales, Sales[Quantity] = 1 ),
Promotion[Promotion Code],
'Date'[Calendar Month end date] //  using month end date
),"Value", ( 1 / 12 ) )

 

and join it in the data model with a date table Promotion table .

 

But you code seem fine to me

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Ultimately, I'm designing a measure here. I don't want to add a new table to the data model. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.