cancel
Showing results for
Did you mean:
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
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!

Proud to be a Super User!

Super User

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.

3 REPLIES 3
Helper II

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

Super User

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.

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!

Proud to be a Super User!

Announcements

#### 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 Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

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