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
Giorgi1989
Advocate II
Advocate 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
Advocate II
Advocate 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 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.

Top Solution Authors