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

 

 

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

 

 

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