Forum Discussion

yaya1974's avatar
yaya1974
Icon for Helper III rankHelper III
2 years ago
Solved

8 month average new column

Hello,  I am trying to calculate my 8 month average (Jan-Aug) to populate for remainder of year (Sep-Dec)

Can anyone help?

MonthActualsAverageTotal
Jan148 1440
Feb222 1440
Mar120 1440
Apr39 1440
May94 1440
Jun73 1440
Jul85 1440
Aug179 1440
Sep 1201440
Oct 1201440
Nov 1201440
Dec 1201440

 

 

Thanks for the help!!!

Lori

  • Irwan's avatar
    Irwan
    2 years ago

    hello yaya1974 

     

    i dont know how your year value in your data, but you can simply add year value as filter.

    Average =
    var _Num = MONTH(CONVERT("2024-"&'Table'[Month]&"-1",DATETIME))
    Return
    IF(
        _Num>8&&VALUE('Table'[Column1])=YEAR(TODAY()),
        AVERAGEX(FILTER(ALL('Table'),VALUE('Table'[Column1])=YEAR(TODAY())),'Table'[Actuals]),
        BLANK()
    )

    as you can see, add in if statement and you can do average on all data before September in on-going year.

     

    But if you want to calculate each year, you can add filter in AVERAGEX

    Average = 
    var _Num = MONTH(CONVERT("2024-"&'Table'[Month]&"-1",DATETIME))
    Return
    IF(
        _Num>8,
        AVERAGEX(FILTER(ALL('Table'),VALUE('Table'[Column1])=YEAR(TODAY())),'Table'[Actuals]),
        BLANK()
    )

     

    Hope this will help.

    Thank you.

10 Replies

  • muhammad_786_1's avatar
    muhammad_786_1
    Icon for Solution Supplier rankSolution Supplier

    You can handle the missing data for the remainder of the year (Sep-Dec) by using this M code:

     

    ā€ƒ

    JanToAug = Table.SelectRows(#"Changed Type", each [MonthNo] >= 1 and [MonthNo] <= 8),
    AvgActuals = List.Average(List.RemoveNulls(JanToAug[Actuals])),
    AddNewCol = Table.AddColumn(#"Changed Type", "NewCol", each if [Actuals] = null then AvgActuals else [Actuals], Int64.Type)

     

    I've also attached a link to a reference file that you can check for more details

     

    File

     

    Best Regards,
    Muhammad Yousaf

     

    If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

     

    LinkedIn

    • yaya1974's avatar
      yaya1974
      Icon for Helper III rankHelper III

      Hello.  Thank you for the help.  I cannot access your file, my company blocked it.  Can you send pbix file?

       

       

  • Oh wait,  plus filter on customer, year, model, finish

    Thank you!

  • hello yaya1974 

     

    is this what you are looking for?

     

    create a calculated column with following DAX.

    Average =
    var _Num = MONTH(CONVERT("2024-"&'Table'[Month]&"-1",DATETIME))
    Return
    IF(
        _Num>8,
        AVERAGEX(ALL('Table'),'Table'[Actuals]),
        BLANK()
    )
     
    Hope this will help.
    Thank you.
    • yaya1974's avatar
      yaya1974
      Icon for Helper III rankHelper III

      Hi.  Thank you.   That works, however, I have multiple years, so having a formula looking at just a specific year does not work.  I need a formula  that will filter on the year and the customer and the model.

      Appreciate your help!

      • Irwan's avatar
        Irwan
        Icon for Super User rankSuper User

        hello yaya1974 

         

        i dont know how your year value in your data, but you can simply add year value as filter.

        Average =
        var _Num = MONTH(CONVERT("2024-"&'Table'[Month]&"-1",DATETIME))
        Return
        IF(
            _Num>8&&VALUE('Table'[Column1])=YEAR(TODAY()),
            AVERAGEX(FILTER(ALL('Table'),VALUE('Table'[Column1])=YEAR(TODAY())),'Table'[Actuals]),
            BLANK()
        )

        as you can see, add in if statement and you can do average on all data before September in on-going year.

         

        But if you want to calculate each year, you can add filter in AVERAGEX

        Average = 
        var _Num = MONTH(CONVERT("2024-"&'Table'[Month]&"-1",DATETIME))
        Return
        IF(
            _Num>8,
            AVERAGEX(FILTER(ALL('Table'),VALUE('Table'[Column1])=YEAR(TODAY())),'Table'[Actuals]),
            BLANK()
        )

         

        Hope this will help.

        Thank you.