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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
firstch
Helper III
Helper III

Is there any way to get Last Year value with this kind of filter

Hi all please help me for dax to get last year value with this kind of filter 

firstch_0-1660153039405.png

this is my current dax

firstch_2-1660153173774.png

this time i have to use another field as slicer which data type is not number

 

Thankyou inadvance

Best Regard

firstch

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@firstch , what is the year here? In such a case I recommend using Rank on sortable column

 

Year Rank = RANKX(all('Date'),'Date'[Year Start date],,ASC,Dense)

 

 

Then have measure
This Year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])))
Last Year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1))

 

YTD

Column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

Measure

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1 && 'Date'[Day of Year] <= Max('Date'[Day of Year])))

 

 

with month

 


YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Month] <= Max('Date'[Month]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Month] <= Max('Date'[Month])))

 

 

Year and month are any numeric or sortable values , month needs to be number in the above case

 

refer custom time intelligence here

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
firstch
Helper III
Helper III

hi @amitchandak 

if this reply is dupplication, im aplogize for it

i have try your solution and its says cant compare text with int

could you please try it with this sample data please:suppose this year is 2550/51

yearproductionYearfruitvalue
25512550/51apple514823
25512550/51guava466683
25512550/51grape741446
25512550/51apple222318
25512550/51guava524553
25512550/51grape842539
25512550/51apple539855
25512550/51guava135614
25512550/51grape858769
25512550/51apple774507
25522551/52guava396773
25522551/52grape662128
25522551/52apple777911
25522551/52guava306057
25522551/52grape979162
25522551/52apple729226
25522552/53guava889772
25522552/53grape841883
25522552/53apple664174
25522552/53guava494220
25522552/53grape353886
25522552/53apple889931
25522552/53guava645981
25522552/53grape840849
25522552/53apple199105
25522552/53guava929611
25522552/53grape692048
25522552/53apple673923
25522552/53guava631041
25532552/53grape55413
25532552/53apple271165
25532552/53guava342101
25532552/53grape42158
25532552/53apple301398
25532552/53guava412220
25532552/53grape181670
25532552/53apple868329

 

best regard

firstch

amitchandak
Super User
Super User

@firstch , what is the year here? In such a case I recommend using Rank on sortable column

 

Year Rank = RANKX(all('Date'),'Date'[Year Start date],,ASC,Dense)

 

 

Then have measure
This Year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])))
Last Year = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1))

 

YTD

Column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

Measure

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank]) && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year Rank]=max('Date'[Year Rank])-1 && 'Date'[Day of Year] <= Max('Date'[Day of Year])))

 

 

with month

 


YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year]) && 'Date'[Month] <= Max('Date'[Month]) ))
LYTD = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]=max('Date'[Year])-1 && 'Date'[Month] <= Max('Date'[Month])))

 

 

Year and month are any numeric or sortable values , month needs to be number in the above case

 

refer custom time intelligence here

 

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

hi @amitchandak thank you for you help

this is my sample data suppose year here is 2550/51

yearproductionYearfruitvalue
25512550/51apple514823
25512550/51guava466683
25512550/51grape741446
25512550/51apple222318
25512550/51guava524553
25512550/51grape842539
25512550/51apple539855
25512550/51guava135614
25512550/51grape858769
25512550/51apple774507
25522551/52guava396773
25522551/52grape662128
25522551/52apple777911
25522551/52guava306057
25522551/52grape979162
25522551/52apple729226
25522552/53guava889772
25522552/53grape841883
25522552/53apple664174
25522552/53guava494220
25522552/53grape353886
25522552/53apple889931
25522552/53guava645981
25522552/53grape840849
25522552/53apple199105
25522552/53guava929611
25522552/53grape692048
25522552/53apple673923
25522552/53guava631041
25532552/53grape55413
25532552/53apple271165
25532552/53guava342101
25532552/53grape42158
25532552/53apple301398
25532552/53guava412220
25532552/53grape181670
25532552/53apple868329

best regard

firstch

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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