Forum Discussion
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
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 😀
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.
7 Replies
- v-cazheng-msft
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.
- admin11
Memorable Member
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
- v-cazheng-msft
Community Support
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.
- aj1973
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
- jaideepnema
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 😀
- admin11
Memorable Member
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
- AnonymousNot 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"))