Forum Discussion

bexbissell's avatar
bexbissell
Icon for Helper I rankHelper I
5 years ago
Solved

How to FILTER a previous year's entry in a Calculated Column?

Hi all,
I have a dimension table that contains entries for each company that manages fund assets. I have created a measure on the table, called AUM (Assets Under Management) that aggregates the total value of Funds from the fact table at the reporting date which works well (side question: is that appropriate to have this measure on the dim table?).

 

Dim Company

IDKeyReport DateNameAUMYoY Change
1232016123112331-12-2016Big Co10000
1232017123112331-12-2017Big Co1200200
1232018123112331-12-2018Big Co1450250
4562016123145631-12-2016Small Co1000
4562017123145631-12-2017Small Co11010
4562018123145631-12-2018Small Co1155


I would now like to create a calculated column called YoY Change to show the Year-on-Year change of the AUM  for each company/report date but I'm struggling with the filtering to retrieve last year's AUM for that ID - I think I've fallen foul of the evaluation context but can't work it out. 

 

 

YoY Change = 
    VAR ThisYearTNAV =
        CALCULATE (
            [AUM],
            FILTER (
                dimCompany,
                MAX(dimCompany[Report Date]) 
            )
        )    
    VAR LastYearTNAV =
        CALCULATE (
            [AUM],
            FILTER (
                dimCompany,
                DATE (YEAR(dimCompany[Report Date])-1, MONTH(dimCompany[Report Date]), DAY(dimCompany[Report Date])) 
            )
        )        
    RETURN ThisYearTNAV - LastYearTNAV

 


Also, I'm not sure how to deal with the YoY change at the start of the data series but that's the least of my worries at the moment.

Many thanks in advance,
Andy


  • Strangely I fell foul of the spam detector so this has just gone live!

    During the radio silence I revisited the code and I have made some changes and found a working solution. This is now a calculated column so only affected on data refresh (bi-annual) so although it's probably not the most efficient or elegent solution it does work (happy to receive critique):

     

    YoY Change = 
    // Calculate last year's Report Date
    VAR LastYear =
        DATE ( dimCompany[Report Date].[Year] - 1, dimCompany[Report Date].[MonthNo], dimCompany[Report Date].[Day] ) 
        
    // Lookup last year's TNAV using 'last year' and the Service Provider's ID
    VAR LastYearTNAV =
        LOOKUPVALUE (
            dimCompany[$ Assets in US],
            dimCompany[Report Date], LastYear,
            dimCompany[ID], dimCompany[ID]
        )
    RETURN
        // If start of data series just return zero
        IF ( LastYearTNAV = 0, 0, dimCompany[$ Assets in US] - LastYearTNAV )

     

     

2 Replies

  • Strangely I fell foul of the spam detector so this has just gone live!

    During the radio silence I revisited the code and I have made some changes and found a working solution. This is now a calculated column so only affected on data refresh (bi-annual) so although it's probably not the most efficient or elegent solution it does work (happy to receive critique):

     

    YoY Change = 
    // Calculate last year's Report Date
    VAR LastYear =
        DATE ( dimCompany[Report Date].[Year] - 1, dimCompany[Report Date].[MonthNo], dimCompany[Report Date].[Day] ) 
        
    // Lookup last year's TNAV using 'last year' and the Service Provider's ID
    VAR LastYearTNAV =
        LOOKUPVALUE (
            dimCompany[$ Assets in US],
            dimCompany[Report Date], LastYear,
            dimCompany[ID], dimCompany[ID]
        )
    RETURN
        // If start of data series just return zero
        IF ( LastYearTNAV = 0, 0, dimCompany[$ Assets in US] - LastYearTNAV )

     

     

    • v-yingjl's avatar
      v-yingjl
      Icon for Community Support rankCommunity Support

      Thanks for your sharing the workaround and it would help members who have the similar issues on the community quickly.

       

      Best Regards,
      Community Support Team _ Yingjie Li