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

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
Super User
Super User

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"
)

 


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

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

Hi @Anonymous,

 

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

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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
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.