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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
MaggieWang
Frequent Visitor

COVID-19 US Tracking Sample - DAX Formula for Daily Death measure

Hi, I am practicing writing DAX formulas and come across the following measure from the "COVID-19 US Tracking Sample" file.

      Daily deaths =
      VAR __CountyName = 'COVID'[County Name]
      VAR __State = 'COVID'[State]
      VAR __Yesterday =  DATEADD(COVID[Date],-1,DAY)
      VAR __TodaysDeaths = 'COVID'[Deaths]
      RETURN  __TodaysDeaths - CALCULATE(
          SUM('COVID'[Deaths]) ,
          FILTER(
              COVID,
              COVID[Date] = __Yesterday &&
              COVID[County Name] = __CountyName &&
              COVID[State] = __State
          )
      ) + 0
Everything makes perfect sense except the last "+ 0" part. Why was the + 0 required at the end of the measure, was it for providing an initial value for doing the SUM? Many thanks.
1 ACCEPTED SOLUTION
CNENFRNL
Community Champion
Community Champion

Hi, @MaggieWang , it's a common trick to convert BLANK() to 0, i.e. when this part of measure

 

__TodaysDeaths - CALCULATE(
          SUM('COVID'[Deaths]) ,
          FILTER(
              COVID,
              COVID[Date] = __Yesterday &&
              COVID[County Name] = __CountyName &&
              COVID[State] = __State
          )
      )

 

returns BLANK(), it can be converted to 0.

Try this measure to see the affect

Test = BLANK() + 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

If you remove +0, you'll see immediately why it's there. And no, it's not necessary unless you want to see 0 instead of BLANK...
CNENFRNL
Community Champion
Community Champion

Hi, @MaggieWang , it's a common trick to convert BLANK() to 0, i.e. when this part of measure

 

__TodaysDeaths - CALCULATE(
          SUM('COVID'[Deaths]) ,
          FILTER(
              COVID,
              COVID[Date] = __Yesterday &&
              COVID[County Name] = __CountyName &&
              COVID[State] = __State
          )
      )

 

returns BLANK(), it can be converted to 0.

Try this measure to see the affect

Test = BLANK() + 0

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors