Search code examples
ssasdax

Check if column is null or blank in DAX


EVALUATE
FILTER
(
SUMMARIZE (
NATURALLEFTOUTERJOIN (
    'Target_Category',
    'Target_Form'
    ),
'Target'[Area],
'Target'[id],
'Target'[Target date],
'Target'[Target Time Range],
'Target_Category'[Origin],
'Target_Category'[Sectotion],
'Target'[Location],
'Target_Category'[Ethencity],
'Target_FormResponse'[Area Used],
'Target'[Description]
),
'Target'[id] = Value("111373268") 
)
ORDEr BY 'Target'[Target Key]
  1. I have the sample DAX query above. Is there away i can manipulate 'Target_FormResponse'[Area Used] such that if it is blank or empty, i return "No" otherwise if its not blank or empty i return "Yes".

In SSRS, i can do something like =IIF(Len(Fields!Form_Response.Value) > 0,"Yes","No") but i want to achieve this at the DAX query level.


Solution

  • If you are satisfied with adding an extra column that contains the "Yes" or "No" values, simple wrap the entire expression in a call to ADDCOLUMNS:

    EVALUATE
    ADDCOLUMNS (
        FILTER (
            SUMMARIZE (
                NATURALLEFTOUTERJOIN ( 'Target_Category', 'Target_Form' ),
                'Target'[Area],
                'Target'[id],
                'Target'[Target date],
                'Target'[Target Time Range],
                'Target_Category'[Origin],
                'Target_Category'[Sectotion],
                'Target'[Location],
                'Target_Category'[Ethencity],
                'Target_FormResponse'[Area Used],
                'Target'[Description]
            ),
            'Target'[id] = VALUE ( "111373268" )
        ),
        "Area Used Yes/No", IF ( 'Target_FormResponse'[Area Used] > 0, "Yes", "No" )
    )
    ORDER BY 'Target'[Target Key]
    

    If you want to get rid of the original column in the output, you'd have to use SELECTCOLUMNS instead, but unfortunately, you'd then have to specify the names of each of the columns you want to keep, so the code ends up a lot longer.