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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

DAX measure running slow

Hi All,

My DAX meaure is working fine on smaller data set but for large volume its taking time , need some help in modifying & fixing performance issue.

Data granularity : order/product/line

Delivered is flag that indicates if ordered item is delivered or not .Order can have multiple item and item can multiple lines .

 

Measures Logic:

 

Success = sum of Delivered order/item

-----------------------------------------------
This is at item level that mean if there are multipe lines for an item in an order it will be counted as 1 thats why total sum is 6 instead of 7

Success :=
CALCULATE (
SUMX (
SUMMARIZE ( Example, Example[Order], 'Example'[Product] ),
CALCULATE ( MAX ( Example[Delivered] ) )
),
ALL ( Example ),
VALUES ( Example[Order] )
)


ProductCount = Total item counts within an order

-----------------------------------------------------------
ProductPerOrder: =
CALCULATE
(
COUNTROWS(VALUES(Example[Product]))
,ALL(Example)
,VALUES(Example[Order])
)


Success% = Sum of Success per order / total item counts per order

--------------------------------------------------------------------------

      Success% := Success / ProductCount

Sample DataSample Data

 




thanks

 

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression to see if it is more performant (and if it gets expected result).

 

Success =
COUNTROWS (
SUMMARIZE (
FILTER ( Example, Example[Delivered] = 1 ),
Example[Order],
Example[Product] 
)
)

 

Add Example[Line] into the Summarize too, if needed

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

8 REPLIES 8
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression to see if it is more performant (and if it gets expected result).

 

Success =
COUNTROWS (
SUMMARIZE (
FILTER ( Example, Example[Delivered] = 1 ),
Example[Order],
Example[Product] 
)
)

 

Add Example[Line] into the Summarize too, if needed

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi,

Thanks for providing alternate approach for the measure,Its working but performance for this measures is almost same as what i was using .Upon testing more it seems the issue is with measure  ProductPerOrder  its not performing as other measure and slowing down the report.

 

Is there any alternate approach that you can suggest to count no of product within an order  other than what i am using.

I am not using ALLEXCEPT for this as ALLEXCEPT only works when Product data is in same table but if Product data is coming from other table its removing filters on colum specified. In my real dataset  product is coming from product dimension.

 

My calculation for ProducstPerORder

ProductsPerOrder =
CALCULATE
(
COUNTROWS(VALUES(Example[Product]))
,ALL(Example)
,VALUES(Example[Order])
)

 

Thanks

@Anonymous there are too many unknowns and your model is not clear, it is hard to find out what is going on? If you put together a sample pbix file, it will be very helpful. You cannot pinpoint performance issues by looking at DAX there could be other factors. If you share pbix with expected result, I will dig into it. I have worked with very complex measures and many large datasets and able to figure out where the problem is, and this particular calculation looks straight forward so there is something else going on.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi ,

Apologize for confusion below is onedrive link for sample data of how my real data model looks like.

I have created the measures that i want and also created one measure   for ProductPerOrderAllEXCEPT   and once you drag that measure to model you will notice what i meant by its not keeping the filters.

I modfied the calculation of ProductPerOrders( taking some help from this post ) and so far its performing really good.

Please let me know if you find any issues with the measures in the pbix or think it can be modified to improve performace.

ProductsPerOrder =
CALCULATE (
COUNTROWS (
SUMMARIZE ( OrderDetails, OrderDetails[Order], 'Product'[Product] )
),
ALL ( OrderDetails ),
VALUES ( OrderDetails[Order] )
)
 
Link for sample pbix.
 
 
Really appreciate you looking into this and helping out and gained s
Regards

Glad to hear it is working better.  I downloaded your pbix and see it only has a few rows.  I thought we might see a bigger dataset for optimizing the measures.  From your different posts, it seems like both measures are working better.  Do you still have an issue?

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


amitchandak
Super User
Super User

@Anonymous , check if this gives you same and fater result

Averagex(summarize(summarize(Example,Example[Order], 'Example'[Product],"_1",MAX ( Example[Delivered] )),[Order],[_1],"_2",count([Product])),Sum([_1]),Sum([_2]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@Anonymous I think you are over complicating the measures, try following:

 

Success :=
CALCULATE (
SUMX (
SUMMARIZE ( Example, Example[Order], 'Example'[Product] ),
CALCULATE ( SUM( Example[Delivered] ) )
)



ProductPerOrder: =
CALCULATE
(
DITINCTCOUNT(Example[Product]),
,ALLEXCEPT(Example, Example[Order])
)

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

Hi ,

Thanks for providing solution  i had the same calculation that you provided before but both the cases it was not working.

 

Success :  If there are multiple lines per item then sum will sum success values at item level 

                but i want to count the success only 1 time so i used MAX

 

ProductPerCount :  This works fine with the sample  but i guess i missed to mentioned one more thing  sorry about that.

                               This is fact tabel  but actual data model has a product dimension and ALLEXCEPT is not working 

                               if we pull  product information from product dimension table  that's why i used VALUES .

https://www.sqlbi.com/articles/using-allexcept-versus-all-and-values/

 

Is there any other approach to achive this ?

 

Regards

 

 

 

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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.