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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
AlexOakman
Frequent Visitor

SUMMARAZE performance / early materialization

Hi, I have a large fact table. I need to calculate a tricky measure. The first step I need to group this table by a certain set of attributes, excluding repetitions, and then find the sum over the resulting table. I use this measure in detailing cumulative dates by month. 
An example of dax:

'📊Measure'[TEST_v1] =

VAR _min = SELECTEDVALUE('Dim date'[firstdate_of_month_key],99999999)
VAR _max = MAX('Dim date'[date_key])

VAR _tbl2 =
ADDCOLUMNS (
SUMMARIZE (
CALCULATETABLE( 'Test_balance', KEEPFILTERS('Test_balance'[date_key]>=_min&&'Test_balance'[date_key]<=_max),REMOVEFILTERS('Dim date')),
'bridge_dpd_addition'[dpd_group_company],
'Test_balance'[prolongation_num_cumulative],
'Test_balance'[amount_usd]
),
"cnt", CALCULATE(DISTINCTCOUNT('Test_balance'[credit_key] ),KEEPFILTERS('Test_balance'[date_key]>=_min&&'Test_balance'[date_key]<=_max),REMOVEFILTERS('Dim date'))
)

VAR _res = SUMX(_tbl2,[amount_usd]*[cnt])

RETURN
_res
-------------------------
or _v2 instead of a _tbl2 I can use 

VAR _tbl1 = SUMMARIZE(    
    CALCULATETABLE( 'Test_balance', KEEPFILTERS('Test_balance'[date_key]>=_min&&'Test_balance'[date_key]<=_max),REMOVEFILTERS('Test_balance')),    
    'bridge_dpd_addition'[dpd_group_company],
    'Test_balance'[prolongation_num_cumulative],
    'Test_balance'[amount_usd],
    'Test_balance'[credit_key] 
    )
VAR _res =   SUMX(_tbl1,[amount_usd])
But in both cases I have early materialization of the data. Is there any way to avoid this?screen.jpg

5 REPLIES 5
AlexOakman
Frequent Visitor

Solved by creating additional columns with a sign 1/0 and a simple Calculate (sum(),flag=1)

tamerj1
Super User
Super User

@AlexOakman 

You may also try

TEST_v1 =
SUMX (
VALUES ( 'Dim date'[firstdate_of_month_key] ),
VAR _min = 'Dim date'[firstdate_of_month_key]
VAR _max =
CALCULATE ( MAX ( 'Dim date'[date_key] ) )
VAR _tbl1 =
FILTER (
CALCULATETABLE ( 'Test_balance', ALL ( 'Test_balance' ) ),
'Test_balance'[date_key] >= _min
&& 'Test_balance'[date_key] <= _max
)
VAR _tbl2 =
SUMMARIZE (
_tbl1,
'bridge_dpd_addition'[dpd_group_company],
'Test_balance'[prolongation_num_cumulative],
'Test_balance'[amount_usd],
'Test_balance'[credit_key]
)
VAR _res =
SUMX ( _tbl2, [amount_usd] )
RETURN
_res
)

Thanks for the advice. Unfortunately the result is the same as for ADDCOLUMN(SUMMARAZE(...)) =(

johnt75
Super User
Super User

If you have a relationship from your date table to the fact table then there is no need to apply the date filters to your fact table and you could simplify the code to

TEST_v1 =
VAR _tbl2 =
    ADDCOLUMNS (
        SUMMARIZE (
            'Test_balance',
            'bridge_dpd_addition'[dpd_group_company],
            'Test_balance'[prolongation_num_cumulative],
            'Test_balance'[amount_usd]
        ),
        "cnt", CALCULATE ( DISTINCTCOUNT ( 'Test_balance'[credit_key] ) )
    )
VAR _res =
    SUMX ( _tbl2, [amount_usd] * [cnt] )
RETURN
    _res

I need to calculate cumulative values for the month by day. Something like that:

AlexOakman_0-1678863405497.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.