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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Need help in optimizing Dax query

Hi Team,

 

I need help in optimizing this query that i am writing in dax 

 

Debug Avg =
AVERAGEX(SUMMARIZE(approxtable,approxtable[Customer_ID],"s",CALCULATE(DIVIDE(SUM(approxtable[Sales]),DISTINCTCOUNT(approxtable[Customer_ID]),0),PATHCONTAINS(TRIM(SUBSTITUTE(SUBSTITUTE(VALUES(approxtable[Control_Id]), ",","|")," ","")),approxtable[Customer_ID]))),[s])

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey, i got the solution. In the previous query, PathContains were taking too long as it has a callback during query execution.

So I did change my query to this

 

AVERAGEX(SUMMARIZE(approxtable,approxtable[Customer_ID],"S",
VAR OrderList = TRIM(SUBSTITUTE(SUBSTITUTE(VALUES(approxtable[Control_Id]),",","|")," ",""))
VAR OrderCount = PATHLENGTH ( OrderList )
VAR HandleNullCount = IF(OrderCount>0,OrderCount,1)
VAR NumberTable = GENERATESERIES ( 1, HandleNullCount, 1 )
VAR OrderTable =
GENERATE (
NumberTable,
VAR CurrentKey = [Value]
RETURN
ROW ( "Key", PATHITEM ( OrderList, CurrentKey ) )
)
VAR GetKeyColumn = SELECTCOLUMNS ( OrderTable, "Key", [Key] )
VAR FilterTable = TREATAS ( GetKeyColumn, approxtable[Customer_ID] )
RETURN
CALCULATE(SUM(approxtable[Sales]), FilterTable )),[S])

 

 

This query executes pretty fast. 

Thanks 

View solution in original post

4 REPLIES 4
v-qiuyu-msft
Community Support
Community Support

Hi @Anonymous,

 

Please modify it as below:

 

Debug Avg =
AVERAGEX (
    SUMMARIZE (
        approxtable,
        approxtable[Customer_ID],
        "s", IF (
            PATHCONTAINS (
                TRIM (
                    SUBSTITUTE (
                        SUBSTITUTE ( VALUES ( approxtable[Control_Id] ), ",", "|" ),
                        " ",
                        ""
                    )
                ),
                approxtable[Customer_ID]
            )
                = TRUE,
            DIVIDE (
                SUM ( approxtable[Sales] ),
                DISTINCTCOUNT ( approxtable[Customer_ID] ),
                0
            )
        )
    ),
    [s]
)

 

Best Regards,
Qiuyun Yu 

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-qiuyu-msft Hi thanks for replying.

 

But somehow this query is not returning any output.

Anonymous
Not applicable

Hey, i got the solution. In the previous query, PathContains were taking too long as it has a callback during query execution.

So I did change my query to this

 

AVERAGEX(SUMMARIZE(approxtable,approxtable[Customer_ID],"S",
VAR OrderList = TRIM(SUBSTITUTE(SUBSTITUTE(VALUES(approxtable[Control_Id]),",","|")," ",""))
VAR OrderCount = PATHLENGTH ( OrderList )
VAR HandleNullCount = IF(OrderCount>0,OrderCount,1)
VAR NumberTable = GENERATESERIES ( 1, HandleNullCount, 1 )
VAR OrderTable =
GENERATE (
NumberTable,
VAR CurrentKey = [Value]
RETURN
ROW ( "Key", PATHITEM ( OrderList, CurrentKey ) )
)
VAR GetKeyColumn = SELECTCOLUMNS ( OrderTable, "Key", [Key] )
VAR FilterTable = TREATAS ( GetKeyColumn, approxtable[Customer_ID] )
RETURN
CALCULATE(SUM(approxtable[Sales]), FilterTable )),[S])

 

 

This query executes pretty fast. 

Thanks 

Anonymous
Not applicable

Is it possible to improve query performance or achieve this in some other manner as this query is still running slow.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.