How can I calculate variance in hours between current records and older timestamped data versions

0 votes

How can I calculate variance in hours between current records and older timestamped data versions?

I have versioned records with timestamps and I want to calculate the difference in hours between the current version and the most recent previous version for each record. I’m looking for a DAX or Power Query approach to calculate this time-based variance efficiently.

4 hours ago in Power BI by Evanjalin
• 34,450 points
4 views

1 answer to this question.

0 votes

Assume you have a table with RecordID, VersionTimestamp, and VersionNumber.

Use EARLIER() or VAR with CALCULATE() to find the previous timestamp per record.

TimeDiffHours =
VAR CurrentRecord = YourTable[RecordID]
VAR CurrentTimestamp = YourTable[VersionTimestamp]
VAR PreviousTimestamp =
    CALCULATE (
        MAX (YourTable[VersionTimestamp]),
        FILTER (
            YourTable,
            YourTable[RecordID] = CurrentRecord &&
            YourTable[VersionTimestamp] < CurrentTimestamp
        )
    )
RETURN
IF (
    ISBLANK (PreviousTimestamp),
    BLANK(),
    DATEDIFF (PreviousTimestamp, CurrentTimestamp, HOUR)
)

Power Query Approach

  1. Sort the table by RecordID and VersionTimestamp.

  2. Group by RecordID, then:

    • Add an Index column within each group.

    • Use the Index to create a new column that shifts the VersionTimestamp down (previous row).

  3. Use a custom column to subtract PreviousTimestamp from CurrentTimestamp in hours:

Duration.Hours([VersionTimestamp] - [PreviousTimestamp])

answered 4 hours ago by anonymous
• 34,450 points

Related Questions In Power BI

+1 vote
2 answers

How can I automate data refreshes in Power BI, and what are the scripting options available?

You can use the Scheduled Refresh option ...READ MORE

answered Nov 20, 2024 in Power BI by Anu
• 3,020 points
444 views
0 votes
1 answer

How can I track changes in data between two different time periods in Power BI?

To track changes in data between time ...READ MORE

answered Dec 18, 2024 in Power BI by anonymous
• 3,020 points

edited Mar 6 381 views
0 votes
1 answer

How can I manage and resolve ambiguous relationships in Power BI data models?

Managing and resolving ambiguity relationships in Power ...READ MORE

answered Dec 30, 2024 in Power BI by Vani
• 3,580 points

edited Mar 6 832 views
0 votes
2 answers

How can I leverage dataflows to optimize data preparation and transformations in Power BI?

Use Power BI Dataflows to centralize and ...READ MORE

answered Jan 23 in Power BI by anonymous
• 24,450 points
348 views
+2 votes
0 answers

Assume referential integrity

1) What is Assume referential integrity? what ...READ MORE

Aug 19, 2019 in Power BI by vnk
2,105 views
+2 votes
1 answer

If Condition

DAX - I assume [Claim_line].[Allowed_Amount_B6] is one ...READ MORE

answered Aug 20, 2019 in Power BI by anonymous
• 33,050 points
2,113 views
+2 votes
1 answer

How to export data to CSV from power bi embedded url ?

Hi Arathi, You can open Visuals from embedded ...READ MORE

answered Aug 23, 2019 in Power BI by anonymous
• 33,050 points
7,090 views
+1 vote
1 answer

Power Bi to Machine Learning Model

Hello @vnk! Power BI only supports Azure Machine ...READ MORE

answered Dec 3, 2019 in Power BI by Priyanka
1,560 views
0 votes
1 answer
+1 vote
1 answer

How can OData be efficiently used in Power BI for connecting to and managing data sources?

Using OData Efficiently in Power BI for ...READ MORE

answered Feb 27 in Power BI by anonymous
• 34,450 points
274 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP