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

Make a measure Measure difference of dates but ignore nulls

I have two dates I would like get the differnece of. One is [First Response] the other is [Created]. In some cases [First Response] is null. When [First Response] is null i would like to ignore it from the calcualtion of the measure. 

 

I've tried writing this measure several different ways. Mostly using CALCULATE. But i usually end up with a "Invaild OADate value" error. I even tried making a condinal column that says TRUE if [First Response] is has a value or FALSE if the [First Response] is null and using this measure

 

Measure =

CALCULATE(sum('Ticket Table'[First Response]),
'Ticket Table'[First Response Has Date]= "TRUE")
- sum('Ticket Table'[Created])
 
This still gave me an Invaild OADate value. 
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @MarioScapellato,

 

You should do a SUMX to make the calculation. You cannot sum dates you need to calculate the difference and then sum.

 

It should look something like this.

 

Days =
SUMX (
    Table1;
    IF (
        Table1[First Response] = BLANK ();
        0;
        Table1[First Response] - Table1[created]
    )
)

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @MarioScapellato,

 

You should do a SUMX to make the calculation. You cannot sum dates you need to calculate the difference and then sum.

 

It should look something like this.

 

Days =
SUMX (
    Table1;
    IF (
        Table1[First Response] = BLANK ();
        0;
        Table1[First Response] - Table1[created]
    )
)

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



thanks @MFelix

 

There's one more issue i'm having though. I'm unable to change this measure to be in a date time format. The end goal is to show this as HH:mm. It appears that using a sumx doen't allow me to change the data type to date/time. Do you know of a way around this?

Try to add the following measure:

 

Measure = (TRUNC([Days];0)) & " " & FORMAT(([Days]-TRUNC([Days];0)*60);"hh:mm")

Not sure if it's ok on calculation.

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



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.