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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
KMalik
Frequent Visitor

create a new column based on another column by date

Hi there, 

 

I'm new to Power BI, can you please advise on how to create a new column with the following logic:

if [Year] is equal to or greater than [current year] then var2 = [Value] else blank

 

[year column] is in date year format yyyy.

KMalik_0-1726923752071.png

I know it might be basic but can't make it work somehow. Thanks for your help.

2 ACCEPTED SOLUTIONS

Heya,

You are comparing two different data types so it doesn't know what to return. I recreated your model and you have to do one of two things:

1. set Year column as Whole number and Value as Decimal number and use this formula:

Forum = 
VAR _year = YEAR(TODAY())
RETURN
IF(Sheet1[Year]>=_year,Sheet1[Value],0)

 

2. Set Year column as Whole number and Value as Text and use this formula:

Forum = 
VAR _year = YEAR(TODAY())
RETURN
IF(Sheet1[Year]>=_year,Sheet1[Value],"0")

 

The second option doesn't really make sense but it also works.

 

Best,

 

PS: if this solved your problem then please mark it as the solution so others can see it



If the post helped then please give it a Kudos and mark it as the solution so others can see it.
Cheers,

View solution in original post

Hi @KMalik 
The year function returns the whole number, you cannot convert it to date format because the engine doesn't know that this is a year, it is just a number for it.

According to the error you are getting, there is issue with the data types.
1. You need the column year to be a whole number not a formatted date.
2 .If the wanted result is a number then it cannot return "" .
The "" is string so the data type should be a text

Ritaf1983_0-1727603687617.png

Ritaf1983_1-1727603751601.png

If you need it as a decimal number with blank cell you can use the formula :

Var2 =
var current_year = YEAR(TODAY())
RETURN
IF([Year]>=current_year,[Value],BLANK())
Ritaf1983_2-1727603851325.png

 

The updated pbix is attached

If my answer was helpful please give me a Kudos and accept as a Solution.


Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

4 REPLIES 4
Ritaf1983
Super User
Super User

Hi @KMalik 
You can use the formula :

Var2 =
var current_year = YEAR(TODAY())
RETURN
IF([Year]>=current_year,[Value],"")
Ritaf1983_0-1726930098486.png

 

The pbix is attached

If my answer was helpful please give me a Kudos and accept as a Solution.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

I tried it but it gives an error and not sure how to proceed with it. Any idea?

 

KMalik_0-1727588930596.png

I was testing a bit and my suspicion is that YEAR(TODAY()) is coming out as a whole number. I tried just creating another variable = YEAR(TODAY()) and it comes out as a whole number and when I changed the format to date the values are incorrect, 2024 changes to 1905.

KMalik_1-1727592101686.png

 

Hi @KMalik 
The year function returns the whole number, you cannot convert it to date format because the engine doesn't know that this is a year, it is just a number for it.

According to the error you are getting, there is issue with the data types.
1. You need the column year to be a whole number not a formatted date.
2 .If the wanted result is a number then it cannot return "" .
The "" is string so the data type should be a text

Ritaf1983_0-1727603687617.png

Ritaf1983_1-1727603751601.png

If you need it as a decimal number with blank cell you can use the formula :

Var2 =
var current_year = YEAR(TODAY())
RETURN
IF([Year]>=current_year,[Value],BLANK())
Ritaf1983_2-1727603851325.png

 

The updated pbix is attached

If my answer was helpful please give me a Kudos and accept as a Solution.


Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Heya,

You are comparing two different data types so it doesn't know what to return. I recreated your model and you have to do one of two things:

1. set Year column as Whole number and Value as Decimal number and use this formula:

Forum = 
VAR _year = YEAR(TODAY())
RETURN
IF(Sheet1[Year]>=_year,Sheet1[Value],0)

 

2. Set Year column as Whole number and Value as Text and use this formula:

Forum = 
VAR _year = YEAR(TODAY())
RETURN
IF(Sheet1[Year]>=_year,Sheet1[Value],"0")

 

The second option doesn't really make sense but it also works.

 

Best,

 

PS: if this solved your problem then please mark it as the solution so others can see it



If the post helped then please give it a Kudos and mark it as the solution so others can see it.
Cheers,

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.