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

DAX Calculate Duration

Hi  

 

I have a table which shows production time. 

 

Always when I get new produced product i get a new entry. I have column with an category and this category can change over the the day couple times. So they change the product which is produced.  I want to calculate the duration between this changes. 

The table looks like this:

 

Ahak_0-1686310038569.png

 

I want to calculate the duration between the ID 5 and 6, 8 and 9 and 13 and 14. 
Maybe additional table which Summarize it by Number of changes and gets the start date and the Enddate? 
How can I extract this timestamps? 

Thank´s!

1 ACCEPTED SOLUTION
Ahak
Frequent Visitor

Hi @nvprasad 

 

I Could it solve it by myself. 

 

many thanks, anyway. 

DurationNew7 = 
VAR CurrentRowID = tabelle2[ID]
VAR CurrentCategory = tabelle2[Category (Text)]
VAR PreviousRowID = CurrentRowID - 1
VAR PreviousRowCategory = 
    CALCULATE(
        MIN(tabelle2[Category (Text)]), 
        FILTER(tabelle2, tabelle2[ID] = PreviousRowID)
    )
VAR PreviousRowTime = 
    CALCULATE(
        MAX(tabelle2[DateandTime]), 
        FILTER(tabelle2, tabelle2[ID] = PreviousRowID)
    )
RETURN 
    IF(
        PreviousRowCategory <> CurrentCategory && NOT(ISBLANK(PreviousRowCategory)),
        (tabelle2[DateandTime] - PreviousRowTime) * 24 * 60, 
        BLANK() 
    )

 

View solution in original post

4 REPLIES 4
Ahak
Frequent Visitor

Hi @nvprasad 

 

I Could it solve it by myself. 

 

many thanks, anyway. 

DurationNew7 = 
VAR CurrentRowID = tabelle2[ID]
VAR CurrentCategory = tabelle2[Category (Text)]
VAR PreviousRowID = CurrentRowID - 1
VAR PreviousRowCategory = 
    CALCULATE(
        MIN(tabelle2[Category (Text)]), 
        FILTER(tabelle2, tabelle2[ID] = PreviousRowID)
    )
VAR PreviousRowTime = 
    CALCULATE(
        MAX(tabelle2[DateandTime]), 
        FILTER(tabelle2, tabelle2[ID] = PreviousRowID)
    )
RETURN 
    IF(
        PreviousRowCategory <> CurrentCategory && NOT(ISBLANK(PreviousRowCategory)),
        (tabelle2[DateandTime] - PreviousRowTime) * 24 * 60, 
        BLANK() 
    )

 

Ahak
Frequent Visitor

Hi @nvprasad , 

 

it could be similar like this post. But the change should be dynamically not only for specific values. Always when a different number to previous number changes. I need the duration

 

Solved: Duration Calculation - Microsoft Fabric Community

 

many thanks, 

Ahak
Frequent Visitor

Hi Parsad, 

 

Here is an DropBoxLink to the pbix file.

 

https://www.dropbox.com/s/iw7f6e52cq6hsfc/Sample_File.pbix?dl=0

 

Many thanks, 

 

 

nvprasad
Solution Sage
Solution Sage

Hi Ahak,

 

Could you please provide some sample data?

 

Appreciate a Kudos! ‌‌
If this helps and resolves the issue, please mark it as a Solution! ‌‌

Regards,
N V Durga Prasad

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