Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

Calculate YTD over multiple dimensions

Hi All,

I need help with YTD calculation over muliple dimesions. I have Entity, Client, Segment and Product dimesions which are text values.  I tried to calculate Rank however, as these are all text values its not working. 

 

EntityClientSegmentProductDateSales
GoogleElizabeth JohnsonKeystoneGoogle Analytics1/28/202038.4923
GoogleMarco MehtaKeystoneGoogle Source2/6/2020868.6342
GoogleRob VerhoffCornerstoneGoogle Analytics4/13/20202171.2942
GoogleShannon CarlsonCornerstoneGoogle Analytics4/17/2020884.7083
GoogleIan JenkinsKeystoneGoogle Analytics4/28/2020413.1463
AppleSydney BennettKeystoneGoogle Source4/29/2020486.7066
AppleChloe YoungKeystoneGoogle Analytics5/8/2020413.1463
AppleWyatt HillKeystoneGoogle Source5/9/2020486.7066
AppleShannon WangKeystoneGoogle Analytics5/12/2020413.1463
AppleClarence RaiKeystoneGoogle Landscape5/13/2020486.7066
AppleLuke LalHealthcare ITGoogle Analytics5/20/20201898.0944
AppleJordan KingHealthcare ITGoogle Analytics5/27/20201265.6195
AppleDestiny WilsonHealthcare ITGoogle Landscape5/28/20201105.81
AppleLuke LalHealthcare ITGoogle Analytics6/16/20201320.6838

4 Replies

  • Anonymous , YTD is over date and should work across dimensions.  You should a date table to make sure work best

     


    YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

     

    or

     

    YTD =
    var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today())
    var _min = eomonth(_max,-1*MONTH(_max))+1
    return
    CALCULATE([net] ,DATESBETWEEN('Date'[Date],_min,_max))

     

     


    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.

    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

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Amit,

    I have used the above formula, however, it is not providing the correct result. Let me rephrase my requirement, I need to provide Month slicer. Suppose I am filtering on May month it should the YTD for May 22 and also last year' YTD i.e. YTD for May 21. 

     

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

     

    Try these formulas:

    YTD =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALLEXCEPT (
                'Table',
                'Table'[Entity],
                'Table'[Client],
                'Table'[Segment],
                'Table'[Product]
            ),
            YEAR ( 'Table'[Date] ) = YEAR ( TODAY () )
                && 'Table'[Date].[Month] = SELECTEDVALUE ( 'Table'[Date].[Month] )
        )
    )
    
    
    LYTD =
    CALCULATE (
        SUM ( 'Table'[Sales] ),
        FILTER (
            ALLEXCEPT (
                'Table',
                'Table'[Entity],
                'Table'[Client],
                'Table'[Segment],
                'Table'[Product]
            ),
            YEAR ( 'Table'[Date] )
                = YEAR ( TODAY () ) - 1
                && 'Table'[Date].[Month] = SELECTEDVALUE ( 'Table'[Date].[Month] )
        )
    )
    

     

    Best Regards,

    Jay

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous 

      Thank you for the response. I tried above DAX formulas however, they are not working correctly. I tried below formula for the current year YTD and it worked fine, however, I am struggling with the following calculations: LY YTD, QTD, LY QTD, MTD and LY MTD.

       
      YTD = CALCULATE(SUM('Sample Data'[Sales]),
      FILTER('Sample Data', 'Sample Data'[Client ID]  = EARLIER('Sample Data'[Client ID] ) &&
      'Sample Data'[Segment ID]  = EARLIER('Sample Data'[Segment ID] ) &&
      'Sample Data'[Product ID]  = EARLIER('Sample Data'[Product ID])&&
      'Sample Data'[Location ID]  = EARLIER('Sample Data'[Location ID])&&
      'Sample Data'[Index] <= EARLIER('Sample Data'[Index])
      )
      )