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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Last month and Last Week DAX Formulas

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

Hi Xioxin,

 

Thanks for the reply. I tried that and still get the same error.

 

The "," is working when I use it in other formulas. Example this works:

 

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

 

 

View solution in original post

7 REPLIES 7
kwatson1
Frequent Visitor

@Greg_Deckler , @Mich I was unable to get this to work as written above, but was able to adjust the parenthises in the formula to get it to work:

B_MEAS_SchedLastWeek =
IF (
YEAR ( [StartDate].[Date] ) = YEAR ( TODAY () )
&& WEEKNUM ( [StartDate].[Date] ) = WEEKNUM ( TODAY() ) -1,
"Yes",
"No"
)
Greg_Deckler
Community Champion
Community Champion

Perhaps:

 

 

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

Last Week =
IF (
YEAR ( [Date] ) = YEAR ( TODAY () )
&& WEEKNUM ( [Date] ) = WEEKNUM ( TODAY ()) -1 ),
"Yes",
"No"
)

 



Follow on LinkedIn
@ 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!:
DAX For Humans

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

Hi, how will you obtain the first date and last dates of last 2 weeks for the first , second and third weeks of January?

Anonymous
Not applicable

Hi Greg, 

 

Thank you for your reply. I tried your suggestion but I get the following error

 

The syntax for ',' is incorrect. (DAX(IF (YEAR ( [Date] ) = YEAR ( TODAY () )&& MONTH( [Date] ) = MONTH( TODAY ()) -1 ),"Yes","No"))).

 

 

Thanks

Anonymous
Not applicable

Hi @Anonymous,

 

It seems like your system not support ',' as separator, you can try to use ';' to instead ','.

 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi Xioxin,

 

Thanks for the reply. I tried that and still get the same error.

 

The "," is working when I use it in other formulas. Example this works:

 

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

 

 

Helo, Correct formula below -there was an extra ) next to today

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

Last Week =
IF (
YEAR ( [Date] ) = YEAR ( TODAY () )
&& WEEKNUM ( [Date] ) = WEEKNUM ( TODAY () -1 ),
"Yes",
"No"
)

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.