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

Previous Week and Previous Month DAX

Hi There,

 

I am fairly new to power BI and trying to figure this out.. I want to create a date table that will have a series how collumns that show a "Yes" or "No" value based on specfied date ranges e.g 1 day ago, 2 days ago, last week, last month etc. 

 

I have managed to get days working fine but I am struggling to get Last Month and Last week. Any idea on the formula I should use for these?

 

 

This is the formula I use to calculate yesterday:

 

Yesterday =
IF (
YEAR ( [Date] ) = YEAR ( TODAY () )
&& DAY ( [Date] ) = DAY ( TODAY () -1 ),
"Yes",
"No"
)

 

Any help would be much appricated!  Thanks

 

 

1 ACCEPTED SOLUTION
v-yuta-msft
Community Support
Community Support

Hi wupdedu,

 

To achieve your requirement, create two calculate columns using DAX formula like pattern below:

Last Month = IF(MONTH([Date]) = MONTH(EDATE(TODAY(), -1)), "Yes", "No") 

Last Week = 
VAR Current_Week = CALCULATE(MAX([Week No]), FILTER(Table1, Table1[Date] = TODAY()))
RETURN
IF([Week No] = Current_Week, "Yes", "No")

Capture.PNG 

 

Regards,

Jimmy Tao

View solution in original post

3 REPLIES 3
v-yuta-msft
Community Support
Community Support

Hi wupdedu,

 

To achieve your requirement, create two calculate columns using DAX formula like pattern below:

Last Month = IF(MONTH([Date]) = MONTH(EDATE(TODAY(), -1)), "Yes", "No") 

Last Week = 
VAR Current_Week = CALCULATE(MAX([Week No]), FILTER(Table1, Table1[Date] = TODAY()))
RETURN
IF([Week No] = Current_Week, "Yes", "No")

Capture.PNG 

 

Regards,

Jimmy Tao

Anonymous
Not applicable

Hi Jimmy,

 

Awesome thanks for that! The month one worked perfectly. The week one was still giving me current the current week.. I adjusted to this and seems to work giving me last week now:

 

Last Week = 
VAR Current_Week = CALCULATE(MAX([Week No]), FILTER(Table1, Table1[Date] = TODAY()))
RETURN
IF([Week No] +1 = Current_Week, "Yes", "No")

 

Thanks for your help!

 

Greg_Deckler
Super User
Super User

See other post 


@ 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...

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.