cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Super User IV
Super User IV

@ImkeF , can you suggest some M code for this



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
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.

Highlighted

The measure give me blank value.

Highlighted
Frequent Visitor

I edit my post with excel and power bi files

Highlighted

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Community Conference

Microsoft Power Platform Communities

Check out the Winners!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors