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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Patv
Helper II
Helper II

Add new column to table in power Query with may be using If-ELSE codition

Hi All, 

I have a simple requirement to create a new column  ( dynemically changes every year) to  one of the existing table.

example: I have two one column in table called Year_id and I want to add new column ( e.g. called new_column) where it shows 1 where year_id is current year and current year+1. so for current year 2022, new column shows 1 for 2022 and 2023, but  Next Year ( in 2023) the new column shows 1 for 2023 and 2024, and so on.. hence I don't have to change the flag every year....

 

pic1.png

I assume it's simple in to write DAX but I am having hardtime so need help here. Thank you in advance!

1 ACCEPTED SOLUTION

Thank you AlexisOlson. That is what I was looking for. I did not know the DAX formula. It worked. 

my formula is like below now and it worked. Thank you again!

 

Column = IF ( TIME_DIMENSION_YEAR[YEAR_ID] IN { ,Year(TODAY())+1, Year(TODAY()) }, 1, 0 )

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

You can use TODAY to get the current date and, thus, the current year.

 

IF ( YEAR ( TODAY() ) IN { Table1[Year_id], Table1[Year_id] - 1 }, 1, 0 )

 

Edit: Sorry. ^This^ is for a calculated column in DAX, not the Power Query language M but you can write similar code there.

if List.Contains({[Year_id], [Year_id]+1}, Date.Year(DateTime.LocalNow())) then 1 else 0

 

Thank you AlexisOlson. That is what I was looking for. I did not know the DAX formula. It worked. 

my formula is like below now and it worked. Thank you again!

 

Column = IF ( TIME_DIMENSION_YEAR[YEAR_ID] IN { ,Year(TODAY())+1, Year(TODAY()) }, 1, 0 )

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.