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

ISBLANK in If to show a zero

I have a DAX Function whereby I display a number based from Today's date minus the last incident date. I have to add the "+0", as I display this result in a Card, and when has never been a zero, and the Card will not display "(Blank)". _DaysSinceLastIncident = IF( ISBLANK([_DateOfLastIncident]), BLANK(), VALUE(TODAY() - [_DateOfLastIncident])) + 0 The issue comes when we choose a location which has never reported an incident, and so we would like to display today's date, minus the date we started to capture (01/01/2017). Currently, they return a "0", which causes confusion as that would mean they have had an incident Today. Many thanks, Gary
1 ACCEPTED SOLUTION
Seward12533
Solution Sage
Solution Sage

I woudl recommend something like the following

 

DateStartedCapture=DATE(2017,1,1)

DaysSinceLastIncident = 
  VAR DeltaDateRAW = TODAY()-[DateOfLastIncident] RETURN
  IF(DELTA=TODAY(),TODAY()-[DateStartedCapture],DELTA)

 

Tipe, you don't need specify the ISBLANK() or return a BLANK() these are implied by DAX

 

IF([DateOfLastIncident],[result]) will do the trick.  just putting a measure in the logical test of an IF is like saying IF "it has a value" then (i.e. NOT(ISBLANK()) and you don't need to specify an ELSE in DAX it will return null (i.e. BLANK()) as the else by default. 

 

Rather than use +0 to force a zero result here is how I like to handle it. 

 

MEASURE = VAR Result = CALCULATE(...) RETURN

IF([RESULT],[RESULT],0)

 

View solution in original post

1 REPLY 1
Seward12533
Solution Sage
Solution Sage

I woudl recommend something like the following

 

DateStartedCapture=DATE(2017,1,1)

DaysSinceLastIncident = 
  VAR DeltaDateRAW = TODAY()-[DateOfLastIncident] RETURN
  IF(DELTA=TODAY(),TODAY()-[DateStartedCapture],DELTA)

 

Tipe, you don't need specify the ISBLANK() or return a BLANK() these are implied by DAX

 

IF([DateOfLastIncident],[result]) will do the trick.  just putting a measure in the logical test of an IF is like saying IF "it has a value" then (i.e. NOT(ISBLANK()) and you don't need to specify an ELSE in DAX it will return null (i.e. BLANK()) as the else by default. 

 

Rather than use +0 to force a zero result here is how I like to handle it. 

 

MEASURE = VAR Result = CALCULATE(...) RETURN

IF([RESULT],[RESULT],0)

 

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.