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

By row, search for a value in another row of the same table

Hello everybody, I'm new to Power BI but I've already done a lot of work by myself thanks to this forum.

I'm pretty sure the problem here is my understanding of DAX and some functions, so I hope you can help me.

 

 

For the context, I'm connected to my JIRA's company API and I have gathered all the status transitions in a table.

For each transition I know the source and the destination. What I want is to be able to calculate the duration of each step.

 

 

To do that, I need to get the elapsed time between the 'Transitionned' date of my current line and the 'Transitionned' date of the earlier transaction for this 'Issue Id'. 

 

I am not able to create a measure that can do that for me.  

You will find below an example for two issues of my table.

 

Thanks in advance !

 

 

IdIssue IdTransitionnedFrom StatusTo Status
178244264962017-01-13 9:41:00 AMOpenIn Analyse
178245264962017-01-13 9:41:00 AMIn AnalyseTo Do
215395264962017-05-18 1:57:00 PMTo DoDone
216558264962017-05-24 1:38:00 PMDoneValidation
216691264962017-05-24 4:20:00 PMValidationDone
180005265662017-01-20 9:46:00 AMOpenIn Analyse
180006265662017-01-20 9:47:00 AMIn AnalyseTo Do
202703265662017-04-06 2:31:00 PMTo DoValidation
202706265662017-04-06 2:33:00 PMValidationTo Do
209420265662017-04-28 4:38:00 PMTo DoIn Progress
209421265662017-04-28 4:38:00 PMIn ProgressValidation
209444265662017-04-28 4:48:00 PMValidationIn Progress
211150265662017-05-04 3:53:00 PMIn ProgressDone
211151265662017-05-04 3:53:00 PMDoneValidation
213229265662017-05-10 5:09:00 PMValidationDone
2 ACCEPTED SOLUTIONS
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Try this MEASURE

 

Duration =
VAR PreviousStepTime =
    CALCULATE (
        MAX ( TableName[Transitionned] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Issue Id] ),
            TableName[Id] < SELECTEDVALUE ( TableName[Id] )
        )
    )
RETURN
    DATEDIFF ( PreviousStepTime, SELECTEDVALUE ( TableName[Transitionned] ), DAY )

Regards
Zubair

Please try my custom visuals

View solution in original post

Hi @Anonymous

 

See the atached file

With your sample data

 

217.png

 

 

 


Regards
Zubair

Please try my custom visuals

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi @Anonymous,

 

Please show your expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hey @Ashish_Mathur, if you look at @Zubair_Muhammad solution, there is a pbix attached, his results are exactly what I was looking for, his measure returns the results I wanted.

 

Thanks for your help, next time I will add the expected results, I should have done it.

Anonymous
Not applicable

Hey @Zubair_Muhammad, I found a problem in the use of your measure in my very special context. The problem is that if I don't display the Id column, the measure won't find the value and return nothing. I wanted to agregate the results to calculate the duration per status, or per issue or per issue type.

 

I know it was not in my orioginal request, that's why I created a new topic: My measure can only work if I display the fields it uses 

HI @Anonymous

 

Try adding a calculated column instead of a MEASURE

 

Duration_Column =
VAR PreviousStepTime =
    CALCULATE (
        MAX ( TableName[Transitionned] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Issue Id] ),
            TableName[Id] < EARLIER ( TableName[Id] )
        )
    )
RETURN
    DATEDIFF ( PreviousStepTime, TableName[Transitionned], DAY )

Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad - apologies, appreciate your original response was a few years ago now but I wondered if you could help me please. 

 

I am trying to find a way to 'look up' a value in a different row of the table based on criteria. I've attached an example file which is a similar structure to my data. 

 

Dogs and Cats example data.xlsx

 

I am trying to write something in a customer/calculated column along the lines of:

 

if [Sale Type] = "Dog" then FIND [ID] = [ID] and [Sale Type] = "Cat" then return the [Date of Sale] however I'm not sure of the correct way to write this in DAX. 

 

Any help would be appreciated as your suggestion on this thread seems relevant to my problem, however i'm struggling to adapt it. 

@Anonymous

 

Hopefully, you won't need the ID now

 

901.png


Regards
Zubair

Please try my custom visuals
Zubair_Muhammad
Community Champion
Community Champion

Hi @Anonymous

 

Try this MEASURE

 

Duration =
VAR PreviousStepTime =
    CALCULATE (
        MAX ( TableName[Transitionned] ),
        FILTER (
            ALLEXCEPT ( TableName, TableName[Issue Id] ),
            TableName[Id] < SELECTEDVALUE ( TableName[Id] )
        )
    )
RETURN
    DATEDIFF ( PreviousStepTime, SELECTEDVALUE ( TableName[Transitionned] ), DAY )

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

Hey @Zubair_Muhammad, you measure is exactly what I needed, thank you so much! Very helpful!

Hi @Anonymous

 

See the atached file

With your sample data

 

217.png

 

 

 


Regards
Zubair

Please try my custom visuals

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.