Forum Discussion

neil37's avatar
neil37
Icon for Advocate I rankAdvocate I
4 years ago
Solved

Year to Date Help

Hello, 

 

Thank you for your assistance on this.

 

I am working on a simple table where I need to calculate:

  1. Year to Date counts from last year (in this case 01/01/2021 to TODAY in 2021)
  2. Current year (in this case 01/01/2022 to TODAY). 
  3. Percentage Change of that Year Over Year

My data is structured as so:

Table Name: 'tbl_Personnel'

DateCategoryCount
01/01/2021Retired4
01/01/2021Resigned5
02/01/2021Retired2
02/01/2021Resigned0
03/01/2021Retired

2

 

My Calendar Table is structured as so : 'Calendar Table'

DateYearMonth NumberMonthYear Month NumberYear MonthQTR
Thursday, July 1, 199919997July23994Jul 99Q3
Thursday, July 2, 199919997July23994Jul 99Q3
Thursday, July 3, 199919997July23994Jul 99Q3

 

Thank you for your assistance!

  • neil37 , if you want to select a date and then want it

    Using Date table and TI

     

    YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
    Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

     

     

    also check

    LYTD QTY forced=
    var _max = date(year(today())-1,month(today()),day(today()))
    return
    if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
    //OR
    //CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
    //TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

     

     

     

    Using today

     

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

    LYTD =
    var _min = date(year(today())-1,1,1)
    var _max = date(year(today())-1,month(today()),day(today()))
    return
    CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max))

     

    Power BI — Year on Year with or Without Time Intelligence
    https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
    https://www.youtube.com/watch?v=km41KfM_0uA

     

    Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
    https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

     

     

2 Replies

  • neil37 , if you want to select a date and then want it

    Using Date table and TI

     

    YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
    Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))

     

     

    also check

    LYTD QTY forced=
    var _max = date(year(today())-1,month(today()),day(today()))
    return
    if(max('Date'[Date])<=_max, CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max), blank())
    //OR
    //CALCULATE(Sum('order'[Qty]),DATESYTD(dateadd('Date'[Date],-1,year)),'Date'[Date]<=_max)
    //TOTALYTD(Sum('order'[Qty]),dateadd('Date'[Date],-1,year),'Date'[Date]<=_max)

     

     

     

    Using today

     

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

    LYTD =
    var _min = date(year(today())-1,1,1)
    var _max = date(year(today())-1,month(today()),day(today()))
    return
    CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _max))

     

    Power BI — Year on Year with or Without Time Intelligence
    https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
    https://www.youtube.com/watch?v=km41KfM_0uA

     

    Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
    https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
    To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.

     

     

    • neil37's avatar
      neil37
      Icon for Advocate I rankAdvocate I

      Using the Today YTD Measures were perfect - THANK YOU!!