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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
thod
Helper I
Helper I

Sum of Average with summarize

Hi,

I have a measure that returns the correct data, both on rows and on the totals in a matrix. However it performs really bad when slicing. Can someone please help identify how I can performance optimize my dax measure and obtain the same result?

Measure = 

VAR MaksPoliceDato = [Seneste dato i fact PoliceBestand]
VAR Tabel =
         SUMMARIZE(
        FILTER('PoliceBestand','PoliceBestand'[DW_SK_Dato] = MaksPoliceDato),
        'PoliceBestand'[DW_EK_Alder],
        'PoliceBestand'[DW_SK_Dato],
        'PoliceBestand'[DW_EK_Kontakt],
        "MyMeasure",
            AVERAGEX(
                FILTER(
            PoliceBestand,
            'PoliceBestand'[DW_EK_Alder] < 150
                && 'PoliceBestand'[DW_EK_Alder] <> -1
                && NOT ( ISBLANK'PoliceBestand'[DW_EK_Alder] ) )
                && 'PoliceBestand'[DW_SK_Dato] = MaksPoliceDato
        ),
                'PoliceBestand'[DW_EK_Alder]
                    *  DISTINCTCOUNT'PoliceBestand'[DW_EK_Kontakt] )
            )
    )
RETURN
    SUMXTabel[MyMeasure] )

Br,
Thomas
8 REPLIES 8
johnt75
Super User
Super User

It's not best practice to use SUMMARIZE to add a calculated column, its better to use that just for grouping and to use ADDCOLUMNS to add the calculated columns. Try

TmpMeasure =
VAR MaksPoliceDato = [Seneste dato i fact PoliceBestand]
VAR Tabel =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( 'PoliceBestand', 'PoliceBestand'[DW_SK_Dato] = MaksPoliceDato ),
            'PoliceBestand'[DW_EK_Alder],
            'PoliceBestand'[DW_SK_Dato],
            'PoliceBestand'[DW_EK_Kontakt]
        ),
        "MyMeasure",
            CALCULATE (
                AVERAGEX (
                    PoliceBestand,
                    'PoliceBestand'[DW_EK_Alder] * DISTINCTCOUNT ( 'PoliceBestand'[DW_EK_Kontakt] )
                ),
                'PoliceBestand'[DW_EK_Alder] < 150
                    && 'PoliceBestand'[DW_EK_Alder] <> -1
                    && NOT ( ISBLANK ( 'PoliceBestand'[DW_EK_Alder] ) )
                        && 'PoliceBestand'[DW_SK_Dato] = MaksPoliceDato
            )
    )
RETURN
    SUMX ( Tabel, [MyMeasure] )

Hi,

Thanks for the quick reply!
The ADDCOLUMNS improved the performance a bit, however the DAX query still spends 24 sec, when having YEAR and MONTH on rows in a table (for 1,5 years).
We are using Direct Query reading from an on prem SSAS.
Any suggestions on how to improve it even more?

There's another couple of tweaks you could make. Rather than filtering the entire table you could just filter the columns you need. You will need to check that this gives the same result as you are currently getting.

Also, in the CALCULATE, you can split the filters on DW_EK_Alder and DW_SK_Dato into separate conditions.

TmpMeasure =
VAR MaksPoliceDato = [Seneste dato i fact PoliceBestand]
VAR Tabel =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER (
                ALL (
                    'PoliceBestand'[DW_EK_Alder],
                    'PoliceBestand'[DW_SK_Dato],
                    'PoliceBestand'[DW_EK_Kontakt],
                    'PoliceBestand'[DW_SK_Dato]
                ),
                'PoliceBestand'[DW_SK_Dato] = MaksPoliceDato
            ),
            'PoliceBestand'[DW_EK_Alder],
            'PoliceBestand'[DW_SK_Dato],
            'PoliceBestand'[DW_EK_Kontakt]
        ),
        "MyMeasure",
            CALCULATE (
                AVERAGEX (
                    PoliceBestand,
                    'PoliceBestand'[DW_EK_Alder] * DISTINCTCOUNT ( 'PoliceBestand'[DW_EK_Kontakt] )
                ),
                'PoliceBestand'[DW_EK_Alder] < 150
                    && 'PoliceBestand'[DW_EK_Alder] <> -1
                    && NOT ( ISBLANK ( 'PoliceBestand'[DW_EK_Alder] ) ),
                'PoliceBestand'[DW_SK_Dato] = MaksPoliceDato
            )
    )
RETURN
    SUMX ( Tabel, [MyMeasure] )

Thanks again.
The new DAX measure performed the same as the other one you gave me. Do you have other suggestions? Or should the whole data model be rethinked?

I can't think of anything else. Direct Query is always going to perform poorly when compared to imported data.

Do you know if there is a way to use SUMMARIZECOLUMNS instead of ADDCOLUMNS AND SUMMARIZE. In Dax Studio it seems to perform better, but I cannot get it to work in my visualizations.
I want a table grouped by year and months with the ability to use different slicers.

You can't use SUMMARIZECOLUMNS in a measure. You can use it to build calculated tables, but that wouldn't react to slicers etc.

Alright, thank you.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.