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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
admin11
Memorable Member
Memorable Member

How to create expression when i click , it will select Year = 2021 ?

Hi All

 

Below expression working fine , when click , it will select , Year = 2021 , Month = 2

 

Current Month -1 =
IF(AND(
MONTH
('Date'[Date])=MONTH(NOW())-1,
YEAR
('Date'[Date])=YEAR(NOW()))
,
FORMAT(EDATE(NOW(),-1),
"MMM-YYYY"))
 
 
admin11_0-1615673755348.png

 

 

May i know how to modify the above expression , so it will only select year = 2021 ?
 
Paul Yeo
 
2 ACCEPTED SOLUTIONS
jaideepnema
Solution Sage
Solution Sage

Hi @admin11 ,

Try this column:

Current Month -1 =
IF(AND(
MONTH
('Date'[Date])=MONTH(NOW())-1,
YEAR
('Date'[Date])=2021))
,
FORMAT(EDATE(NOW(),-1),
"MMM-YYYY"))
 

Please accept this as a solution if your question has been answered !!

Appreciate a Kudos 😀

View solution in original post

v-cazheng-msft
Community Support
Community Support

Hi, @admin11 

You can try the following expression.

 

Current Year =

IF (

    AND (

        MONTH ( 'Date'[Date] )

            = MONTH ( NOW () ) - 1,

        YEAR ( 'Date'[Date] ) = YEAR ( NOW () )

    ),

    FORMAT ( EDATE ( NOW (), -1 ), "YYYY" )

)

 

If it doesn't work, please let me known what fields and visual types you used in your snipping.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? 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

7 REPLIES 7
v-cazheng-msft
Community Support
Community Support

Hi, @admin11 

You can try the following expression.

 

Current Year =

IF (

    AND (

        MONTH ( 'Date'[Date] )

            = MONTH ( NOW () ) - 1,

        YEAR ( 'Date'[Date] ) = YEAR ( NOW () )

    ),

    FORMAT ( EDATE ( NOW (), -1 ), "YYYY" )

)

 

If it doesn't work, please let me known what fields and visual types you used in your snipping.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

@v-cazheng-msft 

@jaideepnema 

@Anonymous 

 

Hi All

 

Thank you for your sharing , it work fine now.

 

I notice that your expression , does not include year 2021 , so i guess , when year =2022 , this when trigger this button , it will turn on year = 2022 right ?

 

Can you share with me how to modify the expression , so that it will turn on March ( Current month ). Meaning it will auto select year=2021 Current year & month = march ( current Month )

 

Paul

 

Hi, @admin11 

It will select current year. If current year is 2021, it will get 2021. If current year is 2022, it will get 2022.

 

If you want get current year and current month, you can try this expression.

 

Current Month =

IF (

    AND (

        MONTH ( 'Date'[Date] ) = MONTH ( NOW () ),

        YEAR ( 'Date'[Date] ) = YEAR ( NOW () )

    ),

    FORMAT ( NOW (), "MMM-YYYY" )

)

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Hello  @admin11 ,

 

try this,

 

Current Month -1 =
IF(OR(
MONTH
('Dates'[Date])=MONTH(NOW())-1,
YEAR
('Dates'[Date])=2021)
,
FORMAT(EDATE(NOW(),-1),
"YYYY"))
jaideepnema
Solution Sage
Solution Sage

Hi @admin11 ,

Try this column:

Current Month -1 =
IF(AND(
MONTH
('Date'[Date])=MONTH(NOW())-1,
YEAR
('Date'[Date])=2021))
,
FORMAT(EDATE(NOW(),-1),
"MMM-YYYY"))
 

Please accept this as a solution if your question has been answered !!

Appreciate a Kudos 😀

@jaideepnema 

Your expression work fine.

But i only wanted to select Current year only.

now your expression also select current month-1.

Can you advise how to make it only select year =2021 and not select Feb ?

 

Paul

aj1973
Community Champion
Community Champion

Hi Paul,

No need to change the expression, select the visual and use Edit interaction to stop other visuals from interacting with the selected visual

aj1973_0-1615681325938.png

 

  

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.