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
Anonymous
Not applicable

Help with dax - ytd

 I have one query  in which i stuck badly. 

 

dateytd value
1/1/202110
2/1/202115
17/1/202127
3/1/20227
5/1/202210
16/1/202215
17/1/202219

 

 

so I wanted output like below,

dateytd valueytd value-last year-for month
1/1/202110null
2/1/202115null
17/1/202127null
3/1/2022727
5/1/20221027
16/1/20221527
17/1/20221927

 

Wanted to make ytd-prev year measure, Where my output is last year max of date's value for that month.

 

It will very helpful if you can ans me.

11 REPLIES 11
tamerj1
Super User
Super User

Hi @Anonymous 
You may try
For Previous Year To Date

 

PYTD =
VAR LastMonthInYearAvailable =
    MAX ( 'Date'[Month Number] )
VAR LastYearAvailable =
    SELECTEDVALUE ( 'Date'[Year Number] )
VAR PreviousYearAvailable = LastYearAvailable - 1
VAR Result =
    CALCULATE (
        [Sales Amount],
        REMOVEFILTERS ( 'Date' ),
        'Date'[Month Number] <= LastMonthInYearAvailable,
        'Date'[Year Number] = PreviousYearAvailable
    )
RETURN
    Result

 

For Max Previous Year To Date

 

PYTD Month Max. =
MAXX (
    VALUES ( 'Date'[Month Number] ),
    IF (
        NOT ISBLANK ( [PYTD] ),
        CALCULATE (
            [Sales PYTD],
            ALLEXCEPT (
                'Date',
                'Date'[Month Number],
                'Date'[Month],
                'Date'[Year Month Number],
                'Date'[Year Month]
            )
        )
    )
)

 

You may need to adjst the names of the columns in the date table or add/remove some columns to/from the ALLEXCEPT depending on you date table structure.

Thank you and have a great day!

Anonymous
Not applicable

whate is 'date'[MOnth number]

The month number 1-12

Do you have multiple years?

Anonymous
Not applicable

Yes. Your solution is giviing me very different thing.

 

Sorry my mistake in explanation may be.

 

Its giving me random value in my actual table.

 

DateYTD(Its measure)
1/1/202110
2/1/20214
13/1/202128
22/1/2021

7 (This is result for

any date of jan/2022)

1/2/202110
6/2/202112
13/2/202155
27/2/202122 

(This is result for

any date of feb/2022)

1/2/2022

17

7/1/20225
11/1/202214
1/2/20223
3/2/202212
13/2/2022

13

 

 

DateYTD(Its measure)YTD(max dates number)(previous year)(same month) 
1/1/202110null
2/1/20214null
13/1/202128null
22/1/20217null
1/2/202110null
6/2/202112null
13/2/202155null
27/2/202122null
1/2/2022

17

7

7/1/202257
11/1/2022147
1/2/2022322
3/2/20221222
13/2/20221322

 

Output should be previous year-same month-for that max date's ytd number

@Anonymous 
Can you please send me your original measure code? It really matters.

Anonymous
Not applicable

SankeyThakkar_7_0-1646925751740.png

this is my issue, I wanted to find max date of same month from last year.

below is my measure,

PYDT =
var _date = date(year(DATEADD(EAS[reportdate],-1,YEAR)),MONTH(DATEADD(EAS[reportdate],-1,YEAR)),10)
var _getdate = calculate(MIN(EAS[reportdate]),ENDOFMONTH(_date))
var result = CALCULATE([NR (YTD) in lakhs],EAS[reportdate] = _getdate && EAS[strategy] <> "XXXX")
return result



tamerj1
Super User
Super User

Hi @Anonymous 

what is your current measure?

Anonymous
Not applicable

@amitchandak  

@ValtteriN 

@AlexisOlson 

 

Please help.

 

Hi,

Try something like this:


Measure 19 =
var _m = MONTH(max('Table (7)'[date]))
var _y = year(max('Table (7)'[date]))-1
return
CALCULATE(MAX('Table (7)'[ytd value]),ALL('Table (7)'[date]), year('Table (7)'[date])=_y,
month('Table (7)'[date])=_m)

 
End result:
ValtteriN_0-1646902674941.png

 


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/







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

Proud to be a Super User!




Anonymous
Not applicable

Sorry my mistake in explanation may be.

 

Its giving me random value in my actual table.

 

DateYTD(Its measure)
1/1/202110
2/1/20214
13/1/202128
22/1/2021

7 (This is result for

any date of jan/2022)

1/2/202110
6/2/202112
13/2/202155
27/2/202122 

(This is result for

any date of feb/2022)

1/2/2022

17

7/1/20225
11/1/202214
1/2/20223
3/2/202212
13/2/2022

13

 

 

DateYTD(Its measure)YTD(max dates number)(previous year)(same month) 
1/1/202110null
2/1/20214null
13/1/202128null
22/1/20217null
1/2/202110null
6/2/202112null
13/2/202155null
27/2/202122null
1/2/2022

17

7

7/1/202257
11/1/2022147
1/2/2022322
3/2/20221222
13/2/20221322

 

Output should be previous year-same month-for that max date's ytd number

Anonymous
Not applicable

Sorry my mistake in explanation may be.

 

Its giving me random value in my actual table.

 

DateYTD(Its measure)
1/1/202110
2/1/20214
13/1/202128
22/1/20217
1/2/202110
6/2/202112
13/2/202155
27/2/202122
1/2/2022

17

7/1/20225
11/1/202214
1/2/20223
3/2/202212
13/2/2022

13

 

 

DateYTD(Its measure)YTD(max dates number)(previous year)(same month) 
1/1/202110null
2/1/20214null
13/1/202128null
22/1/20217null
1/2/202110null
6/2/202112null
13/2/202155null
27/2/202122null
1/2/2022

17

7

7/1/202257
11/1/2022147
1/2/2022322
3/2/20221222
13/2/20221322

 

Output should be previous year-same month-for that max date's ytd number

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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