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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
emiec
Employee
Employee

Help with DAX and Blank

Hi - I wrote the code below to assign an integer-based off L4 date.  For some L4 dates, they are blank.  To deal with blanks, I wrote an ISBLANK statement to return a 0. However, it doesn't.  Just returns blank/null value.   

 

Any suggestions?

 

Compliance  =
VAR now = format(NOW(),"MM/dd/YYYY")
RETURN
    IF(
        ISBLANK(Format(qryCompliance[L4Date],"MM/dd/YYYY")),0,
        SWITCH(
TRUE(),
FORMAT(qryCompliance[L4Date],"MM/dd/YYYY") = now,1,
         Format(qryCompliance[L4Date],"MM/dd/YYYY") < now, 1,
            FOrmat(qryCompliance[L4Date],"MM/dd/YYYY") > now, 2
        )
    
    )
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @emiec ,

 

Please remove the Format to work on it. If we use Format, it will be text format, then we cannot get excepted result we need.

Compliance = 
VAR now =
    DATEVALUE ( NOW () )
RETURN
    IF (
        ISBLANK ( qryCompliance[L4Date] ),
        0,
        SWITCH (
            TRUE (),
            'qryCompliance'[L4Date] = now, 1,
            'qryCompliance'[L4Date] < now, 1,
            'qryCompliance'[L4Date] > now, 2
        )
    )

t.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

6 REPLIES 6
v-frfei-msft
Community Support
Community Support

Hi @emiec ,

 

Please remove the Format to work on it. If we use Format, it will be text format, then we cannot get excepted result we need.

Compliance = 
VAR now =
    DATEVALUE ( NOW () )
RETURN
    IF (
        ISBLANK ( qryCompliance[L4Date] ),
        0,
        SWITCH (
            TRUE (),
            'qryCompliance'[L4Date] = now, 1,
            'qryCompliance'[L4Date] < now, 1,
            'qryCompliance'[L4Date] > now, 2
        )
    )

t.PNG

 

For more details, please check the pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
edhans
Super User
Super User

Just check the field for a blank, not the output of a FORMAT() function.

 

Compliance =
VAR now =
    FORMAT (
        NOW (),
        "MM/dd/YYYY"
    )
RETURN
    IF (
        ISBLANK ( [L4Date] ),
        0,
        SWITCH (
            TRUE (),
            FORMAT (
                qryCompliance[L4Date],
                "MM/dd/YYYY"
            ) = now, 1,
            FORMAT (
                qryCompliance[L4Date],
                "MM/dd/YYYY"
            ) < now, 1,
            FORMAT (
                qryCompliance[L4Date],
                "MM/dd/YYYY"
            ) > now, 2
        )
    )

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Thanks for the suggestion. I removed the FORMAT portion of the code.  However, I'm still getting blank values. 

Are you sure they are blank? Empty is not the same as null, and I just ran a quick test:

isblank(null) is true

Isblank("") is false

 

but both visually show the same in DAX. They do not in Power Query. null shows null, and "" shows an empty cell.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

I tried: 

CALCULATE(IF(ISBLANK(COUNTA(qryCompliance[FedRampSrgL2Date])),0,1))
and it return 0 for the empty/null cells.  If there is a date, it returns 1.
 
However, when I update the formula, it doesn't return a 0 for empty/null cells. 
 
Compliance_WW =
VAR now = format(NOW(),"MM/dd/YYYY")
RETURN
    IF(
        CALCULATE(IF(ISBLANK(COUNTA(qryCompliance[L2Date])),0,1)),
        SWITCH(
TRUE(),
FORMAT(qryCompliance[L2Date],"MM/dd/YYYY") = now, 1,
         Format(qryCompliance[L2Date],"MM/dd/YYYY") < now, 1,
            FOrmat(qryCompliance[L2Date],"MM/dd/YYYY") > now, 2
        )
    
    )

Try this - the COUNTA() is the same as COUNT() in DAX unless it is a boolean field. It doesn't work like it does in Excel. 

 

 

Compliance_WW =
VAR now =
    FORMAT (
        NOW (),
        "MM/dd/YYYY"
    )
RETURN
    IF (
        ISBLANK (
            MAX ( qryCompliance[L2Date] )
        ),
        0,
        SWITCH (
            TRUE (),
            FORMAT (
                qryCompliance[L2Date],
                "MM/dd/YYYY"
            ) = now, 1,
            FORMAT (
                qryCompliance[L2Date],
                "MM/dd/YYYY"
            ) < now, 1,
            FORMAT (
                qryCompliance[L2Date],
                "MM/dd/YYYY"
            ) > now, 2
        )
    )

 

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.