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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
BBIUser
Helper IV
Helper IV

Custom column to retain old cost for previous years and add new cost to the year 2022 and forward

Hello,

 

There is an existing Power BI Query which is used\source for a Power BI report.

Custom Column 

if [Session Admin]= "Not assigned Session" then 0 else [Quantity] * 95

 

95 is the old cost. the new cost will be 100. The formula needs to reflect to show old cost for previous years (2021 - 2018) and add new cost to the year 2022 and forward. I am not into coding. So, can any coding experts show me the formula to retain the old cost and add new cost for current and forward years?

 

BBIUser_0-1670271371940.png

 

Appreciate your help!

1 ACCEPTED SOLUTION
jbwtp
Memorable Member
Memorable Member

Hi @BBIUser 

 

If you want to use dates as comparison, it needs to be in a proper format which PQ would understand. It can be achived using the #date funciton like #date(2023,1,1). If you wan tto add time as well, it would be the #datetime() function, used like #datetime(2023,1,1, 15, 30, 0).

 

You will need to make sure that the other operand (the [Date] in your post above) is also the same type: date when compating to #date() and datetime when comparing to #datetime(). This can be achived by using Date.From() or DateTime.From() respectively.

 

Cheers,

John

View solution in original post

3 REPLIES 3
jbwtp
Memorable Member
Memorable Member

Hi @BBIUser,

 

Please try if this works for you:

if [Session Admin]= "Not assigned Session" then 0 else [Quantity] * (if Date.Year([Date]) > 2021 then 100 else 95)

 

Cheers,

John

Thanks for the reply John @jbwtp . Apprecaite it!

 

How does the formula change if I have to consider date and month? say for example, 

if [Session Admin]= "Not assigned Session" then 0 else [Quantity] * (if [Date] > 6/30/2021 then 100 else 95).

It is throwing Error if I use [Date] > 6/30/2021.

 

I want to actually use the 'Date' column from the screenshot.

Also, not sure if I need to enter the 12:00:00 AM time that is displayed as part of the 'Date' column.

 

Thanks in advance!

jbwtp
Memorable Member
Memorable Member

Hi @BBIUser 

 

If you want to use dates as comparison, it needs to be in a proper format which PQ would understand. It can be achived using the #date funciton like #date(2023,1,1). If you wan tto add time as well, it would be the #datetime() function, used like #datetime(2023,1,1, 15, 30, 0).

 

You will need to make sure that the other operand (the [Date] in your post above) is also the same type: date when compating to #date() and datetime when comparing to #datetime(). This can be achived by using Date.From() or DateTime.From() respectively.

 

Cheers,

John

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.