cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Giorgi1989
Helper II
Helper II

Is Year to Date and Is Year to Previous Month Dax formulae

Dear All,

 

I have a date table, in which I want to add three columns: IsCurrentMonth,IsYTD, and IsYeartoPreviousMonth

 

For current month I have the following DAX formula:

 

IsCurrentMonth =
IF (
YEAR ( 'Date'[Calendar Year/Month Level 01.Key] ) = YEAR ( TODAY () )
&& MONTH ( 'Date'[Calendar Year/Month Level 01.Key] ) = MONTH ( TODAY () ),
"Yes",
"No"
)
 
Could you please advise what would be the easiest way of doing the same thing for YeartoDate and YeartoPreviousMonth?

Many thanks for your invaluable time and help!
2 ACCEPTED SOLUTIONS
ValtteriN
Super User
Super User

Hi,

Here is one example on how to do this if you want to have these columns:

ISYTD =
var _sdate = DATE(YEAR(TODAY()),1,1)
var _edate = TODAY() return
IF(AND('Calendar'[Date]>=_sdate,'Calendar'[Date]<=_edate),1,0)
 
ISYTD_LM =
var _sdate = DATE(YEAR(TODAY()),1,1)
var _edate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,1) return
IF(AND('Calendar'[Date]>=_sdate,'Calendar'[Date]<=_edate),1,0)

By the way, typically you wouldn't need these columns due to functions like DATESYTD() and DATEADD() that you can use as filters in measures.

I hope this helps and if it does consider accepting this as a solution!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

VahidDM
Super User
Super User

Hi @Giorgi1989 

 

Try these codes:

 

IsYTD =
IF(
YEAR( 'Date'[Calendar Year/Month Level 01.Key] ) = YEAR( TODAY() )
&& 'Date'[Calendar Year/Month Level 01.Key] <= TODAY(),
"Yes",
"No"
)
 
 
 
IsYeartoPreviousMonth =
IF(
YEAR( 'Date'[Calendar Year/Month Level 01.Key] ) = YEAR( TODAY() )
&& 'Date'[Calendar Year/Month Level 01.Key]
<= DATE( YEAR( TODAY() ), MONTH( TODAY() ) - 1, DAY( TODAY() ) ),
"Yes",
"No"
)
 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

View solution in original post

3 REPLIES 3
Giorgi1989
Helper II
Helper II

Immensely grateful to both of you. Works well! Accepted as a solution!

VahidDM
Super User
Super User

Hi @Giorgi1989 

 

Try these codes:

 

IsYTD =
IF(
YEAR( 'Date'[Calendar Year/Month Level 01.Key] ) = YEAR( TODAY() )
&& 'Date'[Calendar Year/Month Level 01.Key] <= TODAY(),
"Yes",
"No"
)
 
 
 
IsYeartoPreviousMonth =
IF(
YEAR( 'Date'[Calendar Year/Month Level 01.Key] ) = YEAR( TODAY() )
&& 'Date'[Calendar Year/Month Level 01.Key]
<= DATE( YEAR( TODAY() ), MONTH( TODAY() ) - 1, DAY( TODAY() ) ),
"Yes",
"No"
)
 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

ValtteriN
Super User
Super User

Hi,

Here is one example on how to do this if you want to have these columns:

ISYTD =
var _sdate = DATE(YEAR(TODAY()),1,1)
var _edate = TODAY() return
IF(AND('Calendar'[Date]>=_sdate,'Calendar'[Date]<=_edate),1,0)
 
ISYTD_LM =
var _sdate = DATE(YEAR(TODAY()),1,1)
var _edate = DATE(YEAR(TODAY()),MONTH(TODAY())-1,1) return
IF(AND('Calendar'[Date]>=_sdate,'Calendar'[Date]<=_edate),1,0)

By the way, typically you wouldn't need these columns due to functions like DATESYTD() and DATEADD() that you can use as filters in measures.

I hope this helps and if it does consider accepting this as a solution!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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 Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!