Forum Discussion

janetcpa's avatar
janetcpa
Frequent Visitor
5 years ago
Solved

Calculated Columns using one year average and not calculating if prior year is missing

I have over 30,000 observations of annual financial data dating from 2010 to 2020 that I want to use with my students.  I have a very short example below.  We calculate Return on Equity (ROE) as Net Income divided by average Equity where the average is computed as the prior year ending plus current year ending divided by two. I believe it is easiest with two calculated columns:

 

1 - Calculate Average Equity by taking the current equity plus the previous fiscal year divided by two.  If there is no previous fiscal year shown, then this data should be null or missing.  (note that each company has different years as some companies started in 2015, others went out of business in 2012, etc.)

 

2 - Calculate ROE by taking Net Income divided by the column I just calculated in part 1.  However, if Net income is less than 0 or if Average equity is less than zero, then ROE should be null or missing

 

I want ROE as a calculated column as I want to look at ROE for the industry, etc., and I don't want negative net income or negative equity items included in the analysis numbers.

 

Here is a small sample of the data.

    The Global Company key identifies the company - for example, 1690 is Apple Inc.

    The Fiscal Year is the year I'm looking at (and which will differ from company to company)

    The final two columns are what I want to create with the missing or null items signified with "(null)"

 

Global Company KeyFiscal YearEquityNet Income (Loss)TO CREATE: Average EquityTO CREATE: ROE
169012/31/2010 $                    47,791 $                       14,013 (null)  (null) 
169012/31/2011 $                    76,615 $                       25,922 $                          124,40620.84%
169012/31/2012 $                  118,210 $                       41,733 $                          194,82521.42%
169012/31/2013 $                  123,549 $                       37,037 $                          241,75915.32%
169012/31/2014 $                  111,547 $                       39,510 $                          235,09616.81%
169012/31/2015 $                  119,355 $                       53,394 $                          230,90223.12%
169012/31/2016 $                  128,249 $                       45,687 $                          247,60418.45%
169012/31/2017 $                  134,047 $                       48,351 $                          262,29618.43%
169012/31/2018 $                  107,147 $                       59,531 $                          241,19424.68%
169012/31/2019 $                    90,488 $                       55,256 $                          197,63527.96%
02763812/31/2014 $                    10,599 $                          (256) (null) (null)
02763812/31/2015 $                       9,442 $                          (863) $                            20,041(null)
02763812/31/2016 $                       5,654 $                          (400) $                            15,096(null)
02763812/31/2017 $                       4,523 $                             217 $                            10,1772.13%
02763812/31/2018 $                       5,389 $                             227 $                               9,9122.29%
02763812/31/2019 $                       4,112 $                       (1,125) $                               9,501(null)
00104512/31/2010 $                    (3,945) $                          (471) (null) (null)
00104512/31/2011 $                    (7,111) $                       (1,979) $                          (11,056)(null)
00104512/31/2012 $                    (7,987) $                       (1,876) $                          (15,098)(null)
00104512/31/2013 $                    (2,731) $                       (1,834) $                          (10,718)(null)
00104512/31/2014 $                       2,021 $                         2,882 $                                (710)(null)
00104512/31/2015 $                       5,635 $                         7,610 $                               7,65699.40%
00104512/31/2016 $                       3,785 $                         2,676 $                               9,42028.41%
00104512/31/2017 $                       3,926 $                         1,919 $                               7,71124.89%
00104512/31/2018 $                      (169) $                         1,412 $                               3,75737.58%
00104512/31/2019 $                      (118) $                         1,686 $                                (287)(null)
  • Hi janetcpa 

    You're not dividing by 2 for the average equity in the sample data shown. Add the division by 2 if necessary here:

     

    Avg Equity =
    VAR previousYear_ =
        CALCULATE (
            MAX ( Table1[Fiscal Year] ),
            Table1[Fiscal Year] < EARLIER ( Table1[Fiscal Year] ),
            ALLEXCEPT ( Table1, Table1[Global Company Key] )
        )
    RETURN
        IF (
            NOT ISBLANK ( previousYear_ ),
            Table1[Equity]
                + CALCULATE (
                    SUM ( Table1[Equity] ),
                    Table1[Fiscal Year] = previousYear_,
                    ALLEXCEPT ( Table1, Table1[Global Company Key] )
                )
        )

     

     

     

    ROE =
    IF (
        Table1[Avg Equity] > 0,
        DIVIDE ( Table1[Net Income (Loss)], Table1[Avg Equity] )
    )
    

     

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

2 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    Hi janetcpa 

    You're not dividing by 2 for the average equity in the sample data shown. Add the division by 2 if necessary here:

     

    Avg Equity =
    VAR previousYear_ =
        CALCULATE (
            MAX ( Table1[Fiscal Year] ),
            Table1[Fiscal Year] < EARLIER ( Table1[Fiscal Year] ),
            ALLEXCEPT ( Table1, Table1[Global Company Key] )
        )
    RETURN
        IF (
            NOT ISBLANK ( previousYear_ ),
            Table1[Equity]
                + CALCULATE (
                    SUM ( Table1[Equity] ),
                    Table1[Fiscal Year] = previousYear_,
                    ALLEXCEPT ( Table1, Table1[Global Company Key] )
                )
        )

     

     

     

    ROE =
    IF (
        Table1[Avg Equity] > 0,
        DIVIDE ( Table1[Net Income (Loss)], Table1[Avg Equity] )
    )
    

     

     

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.

     

  • janetcpa's avatar
    janetcpa
    Frequent Visitor

    Thanks - that worked great!  I did forget to divide by 2 and added that to the code and everything works great.  Thanks so much!
    (Note that I can now show my students the difference in overall ROE if they do it as a calculated column versus as a measure and how they need to think through this as you get REALLY different overall results with each one).