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
Anonymous
Not applicable

Create a custom field that calculates duration in hours between rows in the same column

Hi All,

 

I am very new to power bi and all i can only use power query right now. I have a sample data below and i want to calculate the duration in  hours between the current row and the previous row by the product_Category and date field. For example,  i would expect the duration between the 1st and 2nd row for Doritos to give me say 21 hrs even though they have different dates . Please use the main table. Thanks so much for your help

 


Capture.PNG    



2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi Alexis,

 

Thanks for taking the time to respond to my question. I carried out the steps as instructed but i got zeros when i calculated the duration. Could you please clarify step 3 further? Did you mean to to join on all 3 fields? If yes, that's waht i did. Thanks.

 

3. Self-merge on Product_Category and index 0 to index 1 to pull prior DateTime value.

View solution in original post

Merge on two columns. Match Product_Category and one index to Product_Category and the other index. This is just a fancy way of getting the previous row within the same category.

View solution in original post

3 REPLIES 3
AlexisOlson
Super User
Super User

This is a bit of a pain but I'd sketch it like this:

 

1. Create a custom column to combine Date and Time into a single DateTime.

2. Create two indices (one from 1 and one from 0).

3. Self-merge on Product_Category and index 0 to index 1 to pull prior DateTime value.

4. Calculate the difference in time between DateTime and prior DateTime for your duration.

 

Check the post and related links here for more detail on steps 2 and 3.

Anonymous
Not applicable

Hi Alexis,

 

Thanks for taking the time to respond to my question. I carried out the steps as instructed but i got zeros when i calculated the duration. Could you please clarify step 3 further? Did you mean to to join on all 3 fields? If yes, that's waht i did. Thanks.

 

3. Self-merge on Product_Category and index 0 to index 1 to pull prior DateTime value.

Merge on two columns. Match Product_Category and one index to Product_Category and the other index. This is just a fancy way of getting the previous row within the same category.

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.

Top Solution Authors
Top Kudoed Authors