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
StefanH74
Frequent Visitor

calculate average time between 2 database entries in a large database

Hello,

 

I'm trying to create a report where we can see the average cycle time of our products.

every time a cycle is completed on a machine (we have 30), a entry is made in the database.

so I need to compare the entry time with the previous entry (for that product) to get the time for that cycle, and then show in my report the average cycletime per product.

 

data looks like this:

StefanH74_0-1726054395312.png

"Cyclustijd" is a calculated column to get the time (in seconds) between the entry and the previous one.

 

Cyclustijd = 
VAR order_ = vHardwareLog[orderNumber]
VAR created_ = vHardwareLog[created]
VAR created_previous_entry =
CALCULATE(
    MAX(vHardwareLog[created]),
    FILTER(
        ALL(vHardwareLog),
        order_ = vHardwareLog[orderNumber] &&
        created_ > vHardwareLog[created]
    )
)
VAR cyclustijd_ = (created_ - created_previous_entry)*24*60*60

RETURN

IF(
    cyclustijd_ > 300,
    BLANK(),
    cyclustijd_
)

 

and as you can see in the example above, it calculates just fine.

And in my report I can show the average cycle-time.

 

The problem is that I can only run this with about a month of data (±270.000 database-entries)

anything bigger than that, and I get an error: "Not enough memory"

and I would really need it to run with at least a year's worth of data!

 

so if anyone knows a solution for this problem,

or can think of another way to get the result I need, I would greatly appreciate that.

 

Thanx,

Stefan

4 REPLIES 4
Anonymous
Not applicable

Hi @StefanH74 ,

 

You can try changing the calculated column to a metric, which usually reduces memory consumption:

Cyclustijd = 
VAR order_ = SELECTEDVALUE(vHardwareLog[orderNumber])
VAR created_ = SELECTEDVALUE(vHardwareLog[created])
VAR created_previous_entry =
CALCULATE(
    MAX(vHardwareLog[created]),
    FILTER(
        ALL(vHardwareLog),
        vHardwareLog[orderNumber] = order_ &&
        vHardwareLog[created] < created_
    )
)
VAR cyclustijd_ = (created_ - created_previous_entry) * 24 * 60 * 60

RETURN
IF(
    cyclustijd_ > 300,
    BLANK(),
    cyclustijd_
)

 

Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

if only it was that simple....

ahadkarimi
Solution Specialist
Solution Specialist

Hi @StefanH74, give this a try, and if you encounter any issues, let me know.

Here’s a modified version of your DAX, optimizing memory usage:

 

Cyclustijd = 
VAR order_ = vHardwareLog[orderNumber]
VAR created_ = vHardwareLog[created]
VAR created_previous_entry =
    CALCULATE(
        MAX(vHardwareLog[created]),
        REMOVEFILTERS(vHardwareLog),
        vHardwareLog[orderNumber] = order_ && 
        vHardwareLog[created] < created_
    )
VAR cyclustijd_ = (created_ - created_previous_entry) * 86400
RETURN IF(cyclustijd_ <= 300, cyclustijd_)

 

Did I answer your question? If so, please mark my post as the solution! ✔️
Your Kudos are much appreciated! Proud to be a Solution Specialist!

Hello @ahadkarimi ,

 

thanx for the effort, unfortunately this makes no difference. cannot even do 2 months of data.

I think I will need a completely different approach to this problem, (even though I do not see how)

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.