Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

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

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

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

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

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.