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

DiffDate between two dates with where or IF condition

Hi DAX Community!

 

Im new with the Power BI Report Builder, and I'm trying to do following:

 

I am building a Defect Report which is finished to most part, now i want to implement a lead-time table which show the average time it takes a Defect(intern name for Bug) to go from status "created" to status "closed".

Like this : 

2019-10-24 13_01_46-Reporting - darko.ivanovic@dormakaba.com - Outlook.png

 

I have table(StatuschangeTable) which holds every statuschange of an issue.

 

2019-10-24 11_18_11-RemoteDBServer - DCCHSSSRSPRO01.dom01.kaba.grp - Remotedesktopverbindung.png 

As you can see this table is not distinct, for every issueID there are multiple records. And I just need the Diffrence between the changedate when the issue was created and when the issue was closed.

 

So i need a DAX statement which would do this (disregard the syntax in the following example):

 

DateDiff between (Status_changedate where Status_new = "CREATED") and (Status_changedate where Status_old <> "closed" AND Status_new = "closed")) 

 

I have googled this for quite a time but have not really found anything helpfull..

 

I hope YOU can help me with this! 

1 ACCEPTED SOLUTION

I solved my Problem by a workaround. I created a  new column with sql which gives me the dates of the specific statuschanges and then i said DateDiff(CreatedDate, InAnalysisDate, Day)  and its working now like that. 

Then i Also created a Measure which give me an average time of all 21k issues to get 1Value 

View solution in original post

4 REPLIES 4

I solved my Problem by a workaround. I created a  new column with sql which gives me the dates of the specific statuschanges and then i said DateDiff(CreatedDate, InAnalysisDate, Day)  and its working now like that. 

Then i Also created a Measure which give me an average time of all 21k issues to get 1Value 

smpa01
Super User
Super User

@darko_ivanovic  are you looking for this ?

 

 

Measure :=
DATEDIFF (
    CALCULATE (
        MAX ( T[Date] ),
        FILTER ( ALLEXCEPT ( T, T[ID] ), T[Status] = "CREATED" )
    ),
    CALCULATE (
        MAX ( T[Date] ),
        FILTER ( ALLEXCEPT ( T, T[ID] ), T[Status] = "Closed" )
    ),
    DAY
)

Sample Data

IDDateStatus
103531/1/2019CREATED
103532/1/2019Verified
103533/1/2019Planned
103534/1/2019Closed
103541/1/2018CREATED
103542/1/2018Verified
103545/1/2018Closed

 

Capture.PNG

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

i tried it out, doesnt seem to work.. @smpa01  but in your example its working i dont know what im doing wrong 

cmeu
Advocate III
Advocate III

I see you've requested a solution using DAX - would PowerQuery M be acceptable?

I created the following Queries in the query editor: Closed, Created, and Table (with DateDiff)

 

Closed ::

let
    Source = StatusChangeTable,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Status_New] = "Closed"))
in
    #"Filtered Rows"

Created ::

let
    Source = StatusChangeTable,
    #"Filtered Rows" = Table.SelectRows(Source, each ([Status_New] = "CREATED"))
in
    #"Filtered Rows"

Table (with DateDiff) ::

let
    Source = StatusChangeTable,
    #"Removed Columns" = Table.RemoveColumns(Source,{"Status_ChangeDate", "Status_Old", "Status_New"}),
    #"Merge Created" = Table.NestedJoin(#"Removed Columns",{"IssueID"}, Created,{"IssueID"}, "Created", JoinKind.LeftOuter),
    #"Merge Closed" = Table.NestedJoin(#"Merge Created", {"IssueID"}, Closed,{"IssueID"}, "Closed", JoinKind.LeftOuter),
    #"Expanded Created" = Table.ExpandTableColumn(#"Merge Closed", "Created", {"Status_ChangeDate"}, {"Created.Status_ChangeDate"}),
    #"Expanded Closed" = Table.ExpandTableColumn(#"Expanded Created", "Closed", {"Status_ChangeDate"}, {"Closed.Status_ChangeDate"}),
    #"Removed Duplicates" = Table.Distinct(#"Expanded Closed", {"IssueID"}),
    #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "Duration.Days", each Duration.Days([Closed.Status_ChangeDate]-[Created.Status_ChangeDate])),
in
    #"Added Custom"

And simply uncheck the load to report option on any intermediary tables that you don't need

 

10-24-2019 7-35-36 AM.jpg

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.