Forum Discussion

ElvirBotic's avatar
ElvirBotic
Icon for Helper III rankHelper III
5 years ago
Solved

Trying to build Calculated Column for Current Month and Current Year

Hello, looking to build a calculated column that will based on the date table add a new column to show three different statuses Current Month, Previous Month, and then Future Month. So, naturally for...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi  ElvirBotic ,

    Here are the steps you can follow:

    1. Create calculated column.

    Switch =
    var _currentyear=YEAR(TODAY())
    var _currentmonth=MONTH(TODAY())
    var _maxcurrentmonthday=EOMONTH(TODAY(),0)
    var _maxlastmonth=EOMONTH(TODAY(),-2)
    var _switch=
    SWITCH(
        TRUE(),
        YEAR('Table'[Date])=_currentyear&&MONTH('Table'[Date])=_currentmonth,"Current Month",
        YEAR('Table'[Date])=_currentyear&&MONTH('Table'[Date])=_currentmonth-1,"Previous Month",
        'Table'[Date]<=_maxlastmonth,"Previous",
        'Table'[Date]>_maxcurrentmonthday,"Future Month")
    return
    _switch

    2. Result:

    Filter the data to extract representative dates to better view the results

     

    Best Regards,

    Liu Yang

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