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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AliAlHamadi
Frequent Visitor

Help to improve my Dax

Hello, 

I need help to improve my Dax code, it take a lot of my memory and can't apply for huge data it's only work for 20,000 to 30,000 row but my data more than Million row I'm trying to find duration minute between connected and Disconnected for every user.

 

this my code 

 

Duration =
VAR __thislogin = Sheet1 [Time]
VAR __nextlogout =
    CALCULATE (
        MIN (Sheet1 [Time]),
        ALLEXCEPT (Sheet1, Sheet1 [UserID]),
        Sheet1 [Time]> __thislogin,
        Sheet1 [EventType] = "DISCONNECTED"
    )
RETURN
    IF (
        Sheet1 [EventType] = "CONNECTED",
        DATEDIFF (__thislogin, __nextlogout, MINUTE),
        BLANK ()
    )

 and this my data 

 

Capture.PNG

 

 

it will be better to find why doing it in power query editor but in don't a lot of M code.

 

 

I just add sample of my data, only 2000 row

https://drive.google.com/file/d/1gBrDVx7CJJJ2F0cZzLnNdoZetKNV96HW/view?usp=sharing

 

5 REPLIES 5
AliAlHamadi
Frequent Visitor

I edit my post with excel and power bi files

To get the value from the next row, you can use the function from this blogpost: https://www.thebiccountant.com/2018/07/12/fast-and-easy-way-to-reference-previous-or-next-rows-in-po... (the second function has a parameter to get the next row instead of the prevsious row).

 

But you have to apply it on UserID-level like described here: https://www.thebiccountant.com/2018/09/30/memory-efficient-clustered-running-total-in-power-bi/

 

DAX simply needs too much RAM for these kinds of calculations, unfortunately.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

v-xicai
Community Support
Community Support

Hi @AliAlHamadi ,

 

You may create this [Duration] using measure instead of calculated column.

 

Duration =
VAR __thislogin = SELECTEDVALUE( Sheet1 [Time])
VAR __nextlogout =
    CALCULATE (
        MIN (Sheet1 [Time]),
        ALLEXCEPT (Sheet1, Sheet1 [UserID]),
        Sheet1 [Time]> __thislogin,
        Sheet1 [EventType] = "DISCONNECTED"
    )
RETURN
    IF (
       MAX( Sheet1 [EventType] )= "CONNECTED",
        DATEDIFF (__thislogin, __nextlogout, MINUTE),
        BLANK ()
    )

 

You can also refer to the links to improve the performance:

 

https://docs.microsoft.com/en-us/power-bi/guidance/power-bi-optimization

 

https://maqsoftware.com/expertise/powerbi/dax-best-practices

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

The measure give me blank value.

amitchandak
Super User
Super User

@ImkeF , can you suggest some M code for this

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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