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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Okazakipedro
Helper I
Helper I

How can I improve this calculatetable DAX measure performance?

Dear all, good morning.

 

I have a measure I would like to use in my reports but this is taking extremly long to show the visuals. I have a table called Support Category Table and this would have the categories A,B,C and its lower and upper boundaries, thad define in which category a customer should fall into, based on its Revenue or Profit (this specific measure is for profit but I amd oing the same for revenue)

Okazakipedro_0-1740559852163.png

 

Currently, this would be my measure:

category_abcByCumulativeProfit_Profit =

VAR QuartersToAnalyze = CALCULATE(DISTINCTCOUNT('Calendar'[Quarter & Year]),FILTER(
        ALLSELECTED(Fact_JobFinancials),Fact_JobFinancials[CalendarDate] <= MAX(Fact_JobFinancials[CalendarDate]
    )))
   
VAR SalesByProduct =
    CALCULATETABLE (
        ADDCOLUMNS (
            SUMMARIZE ( Fact_JobFinancials, Fact_JobFinancials[Controlling Customer Code] ),
            "@ProdSales", [job_cumulative_totalProfitUSD/EUR]
        ),
        ALLSELECTED ( Fact_JobFinancials )
    )
VAR AllSales =
    CALCULATE (
        [job_cumulative_totalProfitUSD/EUR],
        ALLSELECTED ( Fact_JobFinancials )
    )
VAR ProductsInClass =
    FILTER (
        CROSSJOIN (
            SalesByProduct,
            'Support_CategoryTable'
        ),
            ([job_cumulative_totalProfitUSD/EUR] > 'Support_CategoryTable'[ProfitLowerBoundaries]*QuartersToAnalyze
            && [job_cumulative_totalProfitUSD/EUR] <= 'Support_CategoryTable'[ProfitUpperBoundaries]*QuartersToAnalyze)
        )
VAR Result =
    CALCULATE (
        [job_cumulative_totalProfitUSD/EUR],
        KEEPFILTERS ( ProductsInClass )
    )
RETURN
    Result


But it takes too long if I try to have this together with the cartegory column where my boundaries are defined... 

Anyone have a better solution?

Thank you and Best Regards,

Pedro Okazaki
1 ACCEPTED SOLUTION
freginier
Solution Sage
Solution Sage

Hey there!

 

Your DAX measure performance issue comes from using CALCULATETABLE, CROSSJOIN, and FILTER extensively, which can be resource-intensive. Here's a solution for you:

 

Instead of CROSSJOIN(SalesByProduct, 'Support_CategoryTable'), which generates all possible combinations, use a direct lookup.

category_abcByCumulativeProfit_Profit =
VAR CY_Quarters =
CALCULATE(
DISTINCTCOUNT('Calendar'[Quarter & Year]),
ALLSELECTED(Fact_JobFinancials),
Fact_JobFinancials[CalendarDate] <= MAX(Fact_JobFinancials[CalendarDate])
)

VAR TotalProfit =
CALCULATE(
[job_cumulative_totalProfitUSD/EUR],
ALLSELECTED(Fact_JobFinancials)
)

VAR SelectedCategory =
LOOKUPVALUE(
'Support_CategoryTable'[Category],
'Support_CategoryTable'[ProfitLowerBoundaries], "<=", TotalProfit / CY_Quarters,
'Support_CategoryTable'[ProfitUpperBoundaries], ">=", TotalProfit / CY_Quarters
)

RETURN
SelectedCategory

 

Hopefully this will make faster performance as unnecessary row-by-row filtering is eliminated and accurate category assignment based on cumulative profit and support category table.

 

Hope this helps!

😁😁

View solution in original post

1 REPLY 1
freginier
Solution Sage
Solution Sage

Hey there!

 

Your DAX measure performance issue comes from using CALCULATETABLE, CROSSJOIN, and FILTER extensively, which can be resource-intensive. Here's a solution for you:

 

Instead of CROSSJOIN(SalesByProduct, 'Support_CategoryTable'), which generates all possible combinations, use a direct lookup.

category_abcByCumulativeProfit_Profit =
VAR CY_Quarters =
CALCULATE(
DISTINCTCOUNT('Calendar'[Quarter & Year]),
ALLSELECTED(Fact_JobFinancials),
Fact_JobFinancials[CalendarDate] <= MAX(Fact_JobFinancials[CalendarDate])
)

VAR TotalProfit =
CALCULATE(
[job_cumulative_totalProfitUSD/EUR],
ALLSELECTED(Fact_JobFinancials)
)

VAR SelectedCategory =
LOOKUPVALUE(
'Support_CategoryTable'[Category],
'Support_CategoryTable'[ProfitLowerBoundaries], "<=", TotalProfit / CY_Quarters,
'Support_CategoryTable'[ProfitUpperBoundaries], ">=", TotalProfit / CY_Quarters
)

RETURN
SelectedCategory

 

Hopefully this will make faster performance as unnecessary row-by-row filtering is eliminated and accurate category assignment based on cumulative profit and support category table.

 

Hope this helps!

😁😁

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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