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

why earlier function error

Hi, 

 

I want to calculate the total number of convid cases by date. however the formula below throws an error. I think it might relates to the language setup of my Power BI or my laptop. however, i don't know how to fix it. 

convid.PNG

 

1 ACCEPTED SOLUTION

OK, you generally don't use EARLIER in a measure unless you are using ADDCOLUMNS.

 

So, the next question, what are you trying to accomplish? If you just do SUM([Total confirmed cases of COVID-19] and you put that in a visual along with your Date column, you should get the total confirmed cases for every date. Is that what you want?

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
Greg_Deckler
Super User
Super User

That's odd, the error message doesn't seem to match. First question, is this supposed to be a measure or a column?

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I meant to write a measure. 

 

 

OK, you generally don't use EARLIER in a measure unless you are using ADDCOLUMNS.

 

So, the next question, what are you trying to accomplish? If you just do SUM([Total confirmed cases of COVID-19] and you put that in a visual along with your Date column, you should get the total confirmed cases for every date. Is that what you want?

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

You are right. when I use the earlier function in the column calculation, it works!

 

I also remember the reason behind, ealier function scann the day column line by line to get the current "day" as a filter condition. Therefore it can only be used in column calculation.

 

 

Yes, unless you use ADDCOLUMNS in a measure, then you can use EARLIER when adding a column.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I don't think earlier function is only used in new column. I have seen examples using earlier function to create a measure of sales revenue by product category, and use this measure to create visuals with slicers. 

 

In my case, i want to know how number of crono cases grows from day x to day x+1. Using China and Italy data, it turns out before lockdown, the crono cases increase 30-40% per day, 5 days after lockdown, the increase rate declines. i would like to see if it's the similar case with other countries. therefore i want to create the growth rate measure, track growth rate by days and country in power visual. 

 

Yes, that's why I said generally! 🙂 It can be done, it is just not that common.

 

If I may make a suggestion, I would try something like:

 

 

% Growth = 
  VAR __Date = MAX('Table'[Date])
  VAR __Today = SUM([Total confirmed cases of COVID-19])
  VAR __Yesterday = SUMX(FILTER('Table',REMOVEFILTERS('Table'[Date]),[Date]=(__Date - 1) * 1.),[Total confirmed cases of COVID-19])
RETURN
  DIVIDE(__Today - __Yesterday,__Yesterday,0)

 

You should be able to place that into a visual along with Date.

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

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.