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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Elieekh17
Helper I
Helper I

Optimizing DAX

Dear Community,

 

I have the below DAX that it is slow : couldn't load the data for this visual - out of memory

 

The goal for the dax is to show the SRU_DESCL_EN for the Supplier ERP having the highest best payment terms and if a suppliers ERP ( that's why I put the condition in the return) if it returns blank since an ERP could have many SRU then return the one with highest spend:

Measure =

VAR MaxDaysPaymentTerms = CALCULATE([Best Payment Terms in SG (# Days)], ALL(Suppliers[Supplier (ERP)]))

VAR _sru =
    CALCULATE(
        MAXX(
            FILTER(
                SUMMARIZE(
                    SITE,
                    SITE[SRU_ID],
                    SITE[SRU_DESCL_EN],
                    "DaysPaymentTerms", [Average Weight Theoretical]
                ),
                [DaysPaymentTerms] = MaxDaysPaymentTerms
            ),
            SITE[SRU_DESCL_EN]
        ),
        ALL(Suppliers[Supplier (ERP)]), ALL(SITE)
    )

VAR _topNSRU =
    TOPN(
        1,
        SUMMARIZE(
            SITE,
            SITE[SRU_ID],
            SITE[SRU_DESCL_EN],
            "TotalSpend", SUM(V_RPT_F_PAYTERM[AMOUNT_HT])
        ),
        [TotalSpend], DESC
    )

VAR _highestSpendSRU =
    IF(
        COUNTROWS(_topNSRU) > 0,
        SELECTCOLUMNS(_topNSRU, "SRU_DESCL_EN", SITE[SRU_DESCL_EN]),
        BLANK()
    )

RETURN
    IF(ISBLANK(_sru) && NOT(ISBLANK([Spend])), _highestSpendSRU, _sru)



3 REPLIES 3
audreygerred
Super User
Super User

Hi! It is likely the ALL function taht you are using with CALCULATE. Do you need the measure to ignore page, report, and visual level filtering? If you do not need this measure to ignore any filtering you or the user applied to the report, then ALL is not needed and you can improve the performance by removing.





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

Proud to be a Super User!





Hello @audreygerred , thank you for your reply, yes All function is to remove effect of external slicers/ filters

Unfortunately, using ALL will cause performance decline.





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

Proud to be a Super User!





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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Top Kudoed Authors