Forum Discussion
Need Help: SUMX with filter exceeds the ROW limit
- 1 year ago
I think you can add the time intelligence logic like
Sum less than 0 = VAR BaseTable = CALCULATETABLE ( ADDCOLUMNS ( FILTER ( KEEPFILTERS ( VALUES ( 'FactTable'[amount_base] ) ), 'FactTable'[amount_base] > 0 ), "@num rows", CALCULATE ( COUNTROWS ( 'FactTable' ) ) ), DATESBETWEEN ( DimTable[business_date], [opening_date_range], [closing_date_range] ) ) VAR Result = SUMX ( BaseTable, 'FactTable'[amount_base] * [@num rows] ) RETURN ResultBy wrapping the entire ADDCOLUMNS inside the CALCULATETABLE both the filtering and the count of the number of rows will be done in a filter context which is restricted to the relevant dates.
The thinking behind my approach was to limit the number of rows you have to iterate over to get the sum. By combining the value with the number of occurences you still get the right number but hopefully with fewer rows as there would be a smaller number of unique amounts. Given that it is still returning 5 million rows though that won't be enough.
As you are able to make changes to the model, I think that creating aggregation tables might be the best option, depending on how many dimensions you need to be able to slice by, and the cardinality of those dimensions. If you are just slicing by date then creating a snapshot of each day should be doable, to store the total amount < 0 and the total amount >0 for each day. Your measures would then simply sum this aggregation table.
For more on aggregation techniques you might find https://www.sqlbi.com/articles/optimizing-incremental-inventory-calculations-in-dax/ useful.
thank you so much johnt75 and AlexisOlson. The ideas and the info you provided are very helpful and inspiring.
I would like to avoid making changes to the table schema and keep everything within a calculated measure as much as possible but I guess it just add too much overhead to make that work.