Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
ElvirBotic
Helper III
Helper III

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 August 2021 it should be "Current Month" then for Jan-July be "Previous Month" and anything after August 2021 (i.e. September 2021) "Future Month". My intention is to be able to quickly slice my report with a few selections to show results for previous months because viewers may not want to see current month until the month ends, but still have the ability to show current month if needed. 

 

I have tried using multiple IF statements, but I am thinking I may need to use variables and just do a lot of comparing. Any help/Suggestions?

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

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

vyangliumsft_0-1629183679290.png

 

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

View solution in original post

10 REPLIES 10
v-yangliu-msft
Community Support
Community Support

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

vyangliumsft_0-1629183679290.png

 

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

v-yangliu-msft
Community Support
Community Support

Hi  @ElvirBotic ,

Are you saying that you want to label blank values.

Here are the steps you can follow:

1. Create calculated column.

Column =
var _currentyear=YEAR(TODAY())
var _currentmonth=MONTH(TODAY())
var _switch=
SWITCH(
    TRUE(),
MONTH('Table'[Date])=_currentmonth&&YEAR('Table'[Date])=_currentyear,"Current Month",
'Table'[Date] <DATE(YEAR(TODAY()),MONTH(TODAY()),1),"Previous Month",
MONTH('Table'[Date])>_currentmonth&&YEAR('Table'[Date])>=_currentyear,"Future Month")
return
IF('Table'[Date]=BLANK(),"blank",_switch)

2. Result:

vyangliumsft_0-1628756918927.png

 

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

This would work for one year of data, but I have multiple years of data is there a way for fix to include 2020, 2019, etc?

ElvirBotic
Helper III
Helper III

Yes I have multiple years of data so it makes it harder for me.

@ElvirBotic 

you can try this

Column = if(year('date'[Date])=year(today())&&month('date'[Date])=month(today()),"Current Month",if(year('date'[Date])=year(today())&&month('date'[Date])<month(today()),"Previous Month",if('date'[Date]>EOMONTH(today(),0),"Future Month")))

pls see the attachment below.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




I saw that for 2020 there are a lot of blank values. Is there a way to avoid this? Essentially every date for the date dimension should have a previous, current, and future record. 

@ElvirBotic 

so what do you want to display for past years, you didn't mention that in your description.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Just "Previous" 

@ElvirBotic 

pls try this

Column = if(year('date'[Date])=year(today())&&month('date'[Date])=month(today()),"Current Month",if('date'[Date]<=EOMONTH(today(),-1),"Previous Month",if('date'[Date]>EOMONTH(today(),0),"Future Month")))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




ryan_mayu
Super User
Super User

@ElvirBotic 

is this what you want? I assume you only have one year data in date table. if you have more than one year data, you need to modify the DAX

Column = if(MONTH('Date'[Date])=month(today()),"Current Month",if('Date'[Date]<=EOMONTH(today(),-1),"Previous Month",if('Date'[Date]>EOMONTH(today(),0),"Future Month")))

 1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.