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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
M_SBS_6
Helper V
Helper V

Year to date and previous year to date

Hi, 

I have a date field app_date and I want to create 2 additional colums

 

YTD flag 1 or 0

PYTD flag 1 or 0

 

Can someone please help with the correct dax? 

2 ACCEPTED SOLUTIONS

Is in current year to date?

you can check if the year is the same. This is the dax measure:

YTD = IF(YEAR('YourTable'[app_date]) = YEAR(TODAY()), 1, 0)

YTDPY = IF(YEAR('YourTable'[app_date]) = YEAR(TODAY()) - 1, 1, 0)

View solution in original post

Anonymous
Not applicable

Hi @M_SBS_6 

 

Thanks for the reply from @Gabry , please allow me to provide another insight:

Maybe you can try this:

I create a simple table, it contains two dates.

vzhengdxumsft_1-1710831734065.png

Then I create two measures to satisfy your requirements.

 

 

YTD Flag =
IF ( TOTALYTD ( SUM ( 'Table'[app_date] ), 'Table'[app_date] ) > 0, 1, 0 )
PYTD Flag =
IF (
    TOTALYTD ( SUM ( 'Table'[app_date] ), SAMEPERIODLASTYEAR ( 'Table'[app_date] ) ) > 0,1,0
)

 

 

The result is as follow:

vzhengdxumsft_2-1710831838526.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @M_SBS_6 

 

Thanks for the reply from @Gabry , please allow me to provide another insight:

Maybe you can try this:

I create a simple table, it contains two dates.

vzhengdxumsft_1-1710831734065.png

Then I create two measures to satisfy your requirements.

 

 

YTD Flag =
IF ( TOTALYTD ( SUM ( 'Table'[app_date] ), 'Table'[app_date] ) > 0, 1, 0 )
PYTD Flag =
IF (
    TOTALYTD ( SUM ( 'Table'[app_date] ), SAMEPERIODLASTYEAR ( 'Table'[app_date] ) ) > 0,1,0
)

 

 

The result is as follow:

vzhengdxumsft_2-1710831838526.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Gabry
Super User
Super User

Hi EML,

please explain a little better.

What flag 1 or 0 means?

 

I can't understand what you want to do

If a date is in the current year to date then flag as 1. If it's not in the current year to date, flag as 0.

 

Same principle for previous year to date 

Is in current year to date?

you can check if the year is the same. This is the dax measure:

YTD = IF(YEAR('YourTable'[app_date]) = YEAR(TODAY()), 1, 0)

YTDPY = IF(YEAR('YourTable'[app_date]) = YEAR(TODAY()) - 1, 1, 0)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.