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
James_Barrett
New Member

Calculate and dateadd issue

Hi guys

 

New to Power BI.

 

 

I'm trying to figure out why my CALCULATE and DATEADD formula isn't working.

 

UsersLastWeek = CALCULATE(SUM('Users/New Users'[New Users]),dateadd(FIRSTNONBLANK('CalendarTable'[Week Start],[Week Start]),-7,DAY))

Example Power BI.png

 

 

In the highlighted row I would like to have the previous week's value (42) shown in the UsersLastWeek column. 

 

Any ideas?

 

Thanks,

James

 

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

 

Try this measure

 

=CALCULATE(SUM('Users/New Users'[New Users]),DATESBETWEEN('CalendarTable'[Date],[Last Week Start],[Last Week Start]))

 

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-yulgu-msft
Employee
Employee

Hi @James_Barrett,

 

I tested with above formula, it returned expected result.

 

In your scenario, does 'CalendarTable' list unique continual dates?

 

Please  refer to my steps to get the previous week value.

 

Generate a calendar table. Establish a one to many relationship from calendar table to users table.

CalendarTable = CALENDAR(MIN(Users[Week Start]),MAX(Users[Week Start]))

1.PNG

 

New a measure similar to yours.

UsersLastWeek = CALCULATE(SUM('Users'[New Users]),dateadd(FIRSTNONBLANK('CalendarTable'[Date],CalendarTable[Date]),-7,DAY))

2.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

You need to use EARLIER most likely. See my article on it here, different problem but you can use the same technique. See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

OK, thanks Greg. I'll have a look.

 

 

James

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.