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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
andrew_hardwick
Helper III
Helper III

Comparing dates in a table

I have created a measure to create the difference between 2 dates in seperate tables. The first table holds the records that were created, the second table holds when the fields in table 1 were changed. I want to work out the difference between when the record was created and when it was changed. I have setup a relationship between the 2 tables based on the unique ID.

 

I have created a visualisation in Power BI that holds the Record ID, Open Date, Changed Date, Closed Date and Days to Next Value. Days to Next value should show the difference between either open date and changed date, or open and closed or open and now. The table is showing as below.

 

Record ID     Open Date                       Changed Date                  Closed Date                      DaysToNextValue

00001013     09/02/2017 14:07:26        09/02/2017 16:23:21                                                              1

00001019     14/02/2017 12:40:16        14/02/2017  12:45:21       02/03/2017 14:02:32                     1

00001037     21/02/2017 10:37:18        22/02/2017 13:05:11                                                              2

00001038     21/02/2017 11:45:46                                                 17/05/2017 11:54:04                    380 

00001335     26/04/2017 09:33:39                                                                                                      380

 

The first 3 records are displaying fine as the Changed Date is populate. However where the changed date is empty, I would like to use the Closed date to determine the value, so for line 4 I would expect to see the result 63. For the last line where changed date and closed date are empty, I would like to use the current date, so would expect to see 37.

 

The DAX I am using is-

 

MeasureDaysToNextValue = if(min('History: Problem'[CreatedDate])>0 && min('history: problem'[createddate])>0,CALCULATE(sum('Date'[IsWorkday]),DATESBETWEEN('Date'[Date],min(Problem[BMCServiceDesk__Open_Date_Time__c]),MIN('History: Problem'[CreatedDate]))),if(MIN('Problem'[BMCServiceDesk__Closed_Date_Time__c])>0,CALCULATE(sum('Date'[IsWorkday]),DATESBETWEEN('Date'[Date],min(Problem[BMCServiceDesk__Open_Date_Time__c]),MAX(Problem[BMCServiceDesk__Closed_Date_Time__c]))),CALCULATE(sum('Date'[IsWorkday]),DATESBETWEEN('Date'[Date],min(Problem[BMCServiceDesk__Open_Date_Time__c]),NOW()))))

  

Any suggestions? Thanks.

 

Andy

2 REPLIES 2
v-sihou-msft
Microsoft Employee
Microsoft Employee

@andrew_hardwick

 

In this scenario, you could use calculated column instead of  measure. It will be much easier to achieve you logic. Just apply IF statement like:

 

Column =
1
    * (
        IF (
            Table[Changed Date] <> BLANK (),
            Table[Changed Date],
            IF ( Table[Closed Date] <> BLANK (), Table[Closed Date], NOW () )
        )
            - Table[Open Date]
    )

Regards,

 

Hi @v-sihou-msft

 

I have tried a Column previously but had issues getting the right values, which is why I tried the Measure. However I have followed your advice and am now getting an error stating-

 

A single value for column 'BMCServiceDesk__Closed_Date_Time__c' in table 'problem' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

The DAX is-

 

ColumnDaysToNextValue = 1
    * (
        IF (
            'History: Problem'[ChangedDate] <> BLANK (),
            'History: Problem'[ChangedDate],
            IF ('problem'[BMCServiceDesk__Closed_Date_Time__c] <> BLANK (), 'problem'[BMCServiceDesk__Closed_Date_Time__c], NOW () )
        )
            - 'problem'[BMCServiceDesk__Open_Date_Time__c]
    )

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.