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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Pfoster
Resolver I
Resolver I

Performance Issues with Formula

Hello,

I have made a report where Sales Managers can see their Net Turnover in comparison to an other Scenario. This Delta is split into FX-, Price-, Volume- und Mix-Effects.

With FX- and Mix-Effect, there is no issue, but I think, my Price-Effect and my Volume-Effect are killing the performance, because on the total line, I want to have the sum of the line-results:

Pfoster_0-1765788179465.png

here are the Measures I used:

Price Effect = 
VAR Grain =
    SUMMARIZECOLUMNS(
        'Sales Data'[Company Code],
        'Sales Data'[Material],
        'Sales Data'[Posting period],
        'Sales Data'[Ship To],
        'Sales Data'[Sold To],
        'Sales Data'[Country Code of ship to],
        FocusScenario[Focus Scenario]
    )
VAR Base =
    ADDCOLUMNS(
        Grain,
        "NSPComp",   CALCULATE([NSPComp_LC]),
        "NSPFocus",  CALCULATE([NSPFocus_LC]),
        "FX",        CALCULATE([FX_Rate_CompPeriod]),
        "FocusMT",   CALCULATE([FocusMT])
    )
RETURN
SUMX(
    FILTER(
        Base,
        NOT ( 'Sales Data'[Company Code] IN { "PF3091","PF3HGS","PF3262","PF3267" } ) &&
        'Sales Data'[Material] <> "100222" &&
        [NSPComp]  > 0 &&
        [NSPFocus] > 0
    ),
    ([NSPFocus] - [NSPComp]) * [FX] * [FocusMT] * 1000
)

 

VolEffect = 
VAR BaseTable =
    ADDCOLUMNS (
        SUMMARIZECOLUMNS (
            'Sales Data'[Company Code],
            'Sales Data'[Material],
            'Sales Data'[Posting period],
            'Sales Data'[Ship To],
            'Sales Data'[Sold To],
            'Sales Data'[Country Code of ship to],
            FocusScenario[Focus Scenario]
        ),
        "__RowVolEffect",
            VAR Focus    = [FocusMT]
            VAR CompRaw  = [CompMT]
            VAR CompCalc = IF ( ISBLANK ( CompRaw ), 0, CompRaw )
            VAR BothZeroOrBlank =
                ( ISBLANK ( Focus ) || Focus = 0 ) &&
                ( ISBLANK ( CompRaw ) || CompRaw = 0 )
            RETURN
                IF (
                    BothZeroOrBlank,
                    BLANK(),
                    IF (
                        CompCalc = 0,
                        ( Focus - CompCalc ) * [NSPFocus] * 1000,
                        ( Focus - CompCalc ) * [NSPComp] * 1000
                    )
                )
    )
RETURN
SUMX ( BaseTable, [__RowVolEffect] )

 

Is there a way to get these Measures quicker and more stable? Thank you for any advise! 

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @Pfoster 

For the first measure, filter the table first before summarizing to reduce the number of rows. The measures in the ADDCOLUMNS don't need calculate as itis implicit if a measure is referenced.

Price Effect =
VAR FilteredSales =
    FILTER (
        'Sales Data',
        NOT ( 'Sales Data'[Company Code] IN { "PF3091", "PF3HGS", "PF3262", "PF3267" } ) &&
        'Sales Data'[Material] <> "100222"
    )

VAR Grain =
    SUMMARIZE (
        FilteredSales,
        'Sales Data'[Company Code],
        'Sales Data'[Material],
        'Sales Data'[Posting period],
        'Sales Data'[Ship To],
        'Sales Data'[Sold To],
        'Sales Data'[Country Code of ship to],
        FocusScenario[Focus Scenario] -- this works if FocusScenario is a related table on the one side of a relationship with Sales Data on the many side.
    )

VAR Base =
    ADDCOLUMNS (
        Grain,
        "NSPComp",  [NSPComp_LC],
        "NSPFocus", [NSPFocus_LC],
        "FX",       [FX_Rate_CompPeriod],
        "FocusMT",  [FocusMT]
    )

RETURN
SUMX (
    FILTER (
        Base,
        [NSPComp] > 0 &&
        [NSPFocus] > 0
    ),
    ( [NSPFocus] - [NSPComp] ) * [FX] * [FocusMT] * 1000
)

 

For the second measure, try this:

VolEffect =
VAR BaseTable =
    ADDCOLUMNS (
        SUMMARIZECOLUMNS (
            'Sales Data'[Company Code],
            'Sales Data'[Material],
            'Sales Data'[Posting period],
            'Sales Data'[Ship To],
            'Sales Data'[Sold To],
            'Sales Data'[Country Code of ship to],
            FocusScenario[Focus Scenario]
        ),
        "__RowVolEffect",
            VAR Focus    = [FocusMT]
            VAR CompCalc = [CompMT] + 0
            VAR BothZero =
                ( ISBLANK(Focus) || Focus = 0 ) &&
                CompCalc = 0
            RETURN
                IF (
                    NOT BothZero,
                    IF (
                        CompCalc = 0,
                        ( Focus - CompCalc ) * [NSPFocus] * 1000,
                        ( Focus - CompCalc ) * [NSPComp] * 1000
                    )
                )
    )
RETURN
SUMX(BaseTable, [__RowVolEffect])

Note: DAX optimization isn’t a one-size-fits-all solution and usually requires testing. If this approach doesn’t achieve the desired performance, consider pre-computing or aggregating the results in a calculated table. While this may increase memory usage, it can help the visual render more quickly.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
v-sgandrathi
Community Support
Community Support

Hi @Pfoster,

Thank you @danextian and @amitchandak  for your replie sto the query.

We haven’t heard from you on the last response and was just checking back to see if your query was answered.
Otherwise, will respond back with the more details and we will try to help.

 

Thank you.

 

danextian
Super User
Super User

Hi @Pfoster 

For the first measure, filter the table first before summarizing to reduce the number of rows. The measures in the ADDCOLUMNS don't need calculate as itis implicit if a measure is referenced.

Price Effect =
VAR FilteredSales =
    FILTER (
        'Sales Data',
        NOT ( 'Sales Data'[Company Code] IN { "PF3091", "PF3HGS", "PF3262", "PF3267" } ) &&
        'Sales Data'[Material] <> "100222"
    )

VAR Grain =
    SUMMARIZE (
        FilteredSales,
        'Sales Data'[Company Code],
        'Sales Data'[Material],
        'Sales Data'[Posting period],
        'Sales Data'[Ship To],
        'Sales Data'[Sold To],
        'Sales Data'[Country Code of ship to],
        FocusScenario[Focus Scenario] -- this works if FocusScenario is a related table on the one side of a relationship with Sales Data on the many side.
    )

VAR Base =
    ADDCOLUMNS (
        Grain,
        "NSPComp",  [NSPComp_LC],
        "NSPFocus", [NSPFocus_LC],
        "FX",       [FX_Rate_CompPeriod],
        "FocusMT",  [FocusMT]
    )

RETURN
SUMX (
    FILTER (
        Base,
        [NSPComp] > 0 &&
        [NSPFocus] > 0
    ),
    ( [NSPFocus] - [NSPComp] ) * [FX] * [FocusMT] * 1000
)

 

For the second measure, try this:

VolEffect =
VAR BaseTable =
    ADDCOLUMNS (
        SUMMARIZECOLUMNS (
            'Sales Data'[Company Code],
            'Sales Data'[Material],
            'Sales Data'[Posting period],
            'Sales Data'[Ship To],
            'Sales Data'[Sold To],
            'Sales Data'[Country Code of ship to],
            FocusScenario[Focus Scenario]
        ),
        "__RowVolEffect",
            VAR Focus    = [FocusMT]
            VAR CompCalc = [CompMT] + 0
            VAR BothZero =
                ( ISBLANK(Focus) || Focus = 0 ) &&
                CompCalc = 0
            RETURN
                IF (
                    NOT BothZero,
                    IF (
                        CompCalc = 0,
                        ( Focus - CompCalc ) * [NSPFocus] * 1000,
                        ( Focus - CompCalc ) * [NSPComp] * 1000
                    )
                )
    )
RETURN
SUMX(BaseTable, [__RowVolEffect])

Note: DAX optimization isn’t a one-size-fits-all solution and usually requires testing. If this approach doesn’t achieve the desired performance, consider pre-computing or aggregating the results in a calculated table. While this may increase memory usage, it can help the visual render more quickly.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
amitchandak
Super User
Super User

@Pfoster , ideally, for this level of calculation, I would expect an aggregated table 

 

But you can move this file in summarizecolumns 

NOT ( 'Sales Data'[Company Code] IN { "PF3091","PF3HGS","PF3262","PF3267" } ) &&
'Sales Data'[Material] <> "100222"

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.