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
Anonymous
Not applicable

Return N/A value

Hi,

 

Just wondering if anyone cn help with my query, I need the below DAX to return N/A when the current year is not selected on the filter I have on the page. Wehn I select 2020 for instance I get Blank in my card visual 

 

Prev Months Tickets = VAR CurrentMonth = MONTH(TODAY())

VAR currntYear =  YEAR(TODAY())

VAR LastDay = EOMONTH(TODAY()),0)

VAR Firstday = DATE(CurrentYear, CurrentMonth,1)

 

VAR ContextTable = 

CALCULATETABLE(

      VALUES(Dates[Date]),

      Filter(Dates,

                Dates[Date] >= Firstday &&

                Dates[Date] <= LastDay))

 

RETURN

CALCUALTE([Total Tickets],

DATEADD(ContextTable, -1, MONTH))

 

Many thanks in advance

      

 

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

This is a bit annoying, I wish the card had a setting for alternate text to return when the result is blank. But you can do this in a measure by explicitly checking for the blank value

 

eg

 

Prev Months Tickets = VAR CurrentMonth = MONTH(TODAY())

VAR currntYear =  YEAR(TODAY())

VAR LastDay = EOMONTH(TODAY()),0)

VAR Firstday = DATE(CurrentYear, CurrentMonth,1)

 

VAR ContextTable = 

CALCULATETABLE(

      VALUES(Dates[Date]),

      Filter(Dates,

                Dates[Date] >= Firstday &&

                Dates[Date] <= LastDay))

var result = 

CALCUALTE([Total Tickets],

DATEADD(ContextTable, -1, MONTH))

RETURN IF( ISBLANK( result ), "N/A", result)

 

 

You could also look at using the COALESCE function for the last line

 

RETURN COALESCE( result , "N/A" )

 

View solution in original post

2 REPLIES 2
d_gosbell
Super User
Super User

This is a bit annoying, I wish the card had a setting for alternate text to return when the result is blank. But you can do this in a measure by explicitly checking for the blank value

 

eg

 

Prev Months Tickets = VAR CurrentMonth = MONTH(TODAY())

VAR currntYear =  YEAR(TODAY())

VAR LastDay = EOMONTH(TODAY()),0)

VAR Firstday = DATE(CurrentYear, CurrentMonth,1)

 

VAR ContextTable = 

CALCULATETABLE(

      VALUES(Dates[Date]),

      Filter(Dates,

                Dates[Date] >= Firstday &&

                Dates[Date] <= LastDay))

var result = 

CALCUALTE([Total Tickets],

DATEADD(ContextTable, -1, MONTH))

RETURN IF( ISBLANK( result ), "N/A", result)

 

 

You could also look at using the COALESCE function for the last line

 

RETURN COALESCE( result , "N/A" )

 

Anonymous
Not applicable

Hi @d_gosbell 

 

Thank you so much both solutions work perfectly, plus I learnt the COALESCE function which is even better so thanks again.

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.