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
admin11
Memorable Member
Memorable Member

How to modify LYTD Qty expression , So that it will display Last Year To Date Qty ?

Hi All

 

@Vera_33  share with me below expression working fine , in order to return Qty for Jan - Mar 2021 , user need to manually tick on year=2021 , month =3 :-

 

CNT_LYTD_COY = TOTALYTD(Distinctcount(SALES[Customer Name]),DATEADD('Date'[Date], -1, YEAR ), ALL( 'Date' ) )
 
Can pls help me modify the above expression , so that when i filter year = 2021 and month = march ( user don't need tick year=2021 , month = 3) , it will return count qty from 2021 Jan till March.
 
Paul
 
2 ACCEPTED SOLUTIONS

@admin11 ,

 

Try like (small change in YTD and LYTD)

 

YTD=
var _min = date(year(today()),1,1)
var _day = today()
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] =year(Today()) && 'Date'[Day of Year] <= _day) )

 

 

 

 

LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _max))

 

View solution in original post

@Vera_33 @amitchandak 

 

Below is the 2 expression work fine , user don't need to filter year & month :-

 

CNT CUST ID LYTD_FINAL =
var _max = date(year(today())-1,month(today()),day(today()))
return
TOTALYTD(DISTINCTCOUNT('SALES'[CUST_ID]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)


CNT CUST ID YTD_FINAL =
var _max = today()
return
calculate(TOTALYTD(DISTINCTCOUNT('SALES'[CUST_ID]),'Date'[Date]),filter('Date','Date'[Date]<=_max))
 
Thank you both of you helping.
 
Paul
 
 

View solution in original post

7 REPLIES 7
Vera_33
Resident Rockstar
Resident Rockstar

Hi Paul,

 

I actually don't quite understand your question, why you filter the date and the user needs to filter again? Did @amitchandak answer your question?

@Vera_33 @amitchandak 

 

Below is the 2 expression work fine , user don't need to filter year & month :-

 

CNT CUST ID LYTD_FINAL =
var _max = date(year(today())-1,month(today()),day(today()))
return
TOTALYTD(DISTINCTCOUNT('SALES'[CUST_ID]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)


CNT CUST ID YTD_FINAL =
var _max = today()
return
calculate(TOTALYTD(DISTINCTCOUNT('SALES'[CUST_ID]),'Date'[Date]),filter('Date','Date'[Date]<=_max))
 
Thank you both of you helping.
 
Paul
 
 

@Vera_33 

your exxpression below is working fine :-

CNT_LYTD_COY = TOTALYTD(Distinctcount(SALES[Customer Name]),DATEADD('Date'[Date], -1, YEAR ), ALL( 'Date' ) )
But the user need to slect year=2021 , month=3 in order to get LYTD total. If user does not select year=2021 , month =3 , it will return whole year value. 
As you aware that YTD have no issue. 
At the end i need to compare the growth rate account. 
 
Hope you understand.
 
@amitchandak  Solution is correct , it is what i need , it will return LYTD from Jan - march 2021. But due to small error , it display null , now i waiting for him to help me correction.
Paul Yeo 
amitchandak
Super User
Super User

@admin11 , YTD and LYTD , without use selecting a date

 

YTD=
var _min = date(year(today()),1,1)
var _day = datediff(_min, today(),day)+1
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] =year(Today()) && 'Date'[Day of Year] <= _day) )

LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _day))

@amitchandak 

Thank you so much for your sharing. i try to use your expression i get null display.

 

COUNT YTD AMIT =
var _min = date(year(today()),1,1)
var _day = datediff(_min, today(),day)+1
return
CALCULATE(Distinctcount('SALES'[CUST_ID]), FILTER(ALL('Date'),'Date'[Year] =year(Today()) && 'Date'[Date] <= _day) )

admin11_0-1615277115376.png

My PBI file :-

https://www.dropbox.com/s/hh9isfpxb99m5t9/PBT_V2021_353%20LYTD%20COUNT.pbix?dl=0

 

Paul

@admin11 ,

 

Try like (small change in YTD and LYTD)

 

YTD=
var _min = date(year(today()),1,1)
var _day = today()
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] =year(Today()) && 'Date'[Day of Year] <= _day) )

 

 

 

 

LYTD =
var _min = date(year(today())-1,1,1)
var _max = date(year(today())-1,month(today()),day(today()))
var _day = datediff(_min, _max,day)+1
return
CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Year] = year(Today())-1 && 'Date'[Day of Year] <= _max))

 

@amitchandak 

Thank you very much , it work fine now.

Paul

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.