cancel
Showing results for 
Search instead for 
Did you mean: 
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!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

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!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition
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!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition
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!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition
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!!!
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Learn Power BI 2nd Edition

Helpful resources

Announcements
Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

Power BI Dev Camp Session 22 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!