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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

How to use date function in statment

Hello,

 

im trying to write if statment with date function, however im getting error . the porpose for the statment to give and date before "31/12/2009" as number 0 then give following date. below the statment i wrote in custome column power bi. & the tabel below as example from my source.

Base column= if (
[Sales-DATE]= null ) then

""
else
if (
Date.Day ( [Sales-DATE] ) <=Date.Day(2009,12,31)) then
0
else [Year.Base]

Example

Sales-DATEYear.BaseOutput 
01/03/201420142014
NullNull 
20/05/201520152015
10/09/200820080

 

 
 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

What data type is your [Sales-DATE]?

26.png

If your [Sales-DATE] is text type, please see the following calculated column.

 

Base column =
VAR _month =
    RIGHT ( LEFT ( [Sales-DATE], 5 ), 2 )
VAR _day =
    LEFT ( [Sales-DATE], 2 )
VAR _year =
    RIGHT ( [Sales-DATE], 4 )
RETURN
    IF (
        [Sales-DATE] <> "Null",
        IF ( DATE ( _year, _month, _day ) <= DATE ( 2009, 12, 31 ), 0, [Year.Base] )
    )

 

27.png

 

Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

You can check the details in the attachment.

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

What data type is your [Sales-DATE]?

26.png

If your [Sales-DATE] is text type, please see the following calculated column.

 

Base column =
VAR _month =
    RIGHT ( LEFT ( [Sales-DATE], 5 ), 2 )
VAR _day =
    LEFT ( [Sales-DATE], 2 )
VAR _year =
    RIGHT ( [Sales-DATE], 4 )
RETURN
    IF (
        [Sales-DATE] <> "Null",
        IF ( DATE ( _year, _month, _day ) <= DATE ( 2009, 12, 31 ), 0, [Year.Base] )
    )

 

27.png

 

Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

You can check the details in the attachment.

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

themistoklis
Community Champion
Community Champion

@Anonymous 

 

It seems that you are trying to achieve this using Power Query.

 

Go to Power Query editor --> Add Column --> Custom Column and add the following formula:

 

Add Custom Column = if [Sales-DATE] = null then "" else if [Sales-DATE] ) <=#date(2009, 12, 31) then 0 else [Year.Base]

 

Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please try the below.

 

Base column = IF( 'Table'[Sales-DATE] = BLANK(), BLANK(),
IF('Table'[Sales-DATE] <= DATE(2009,12,31), 0, 'Table'[Year.Base]))
 
The above is for the calculated column.
 
Did I answer your question? Mark my post as a solution!
Appreciate your Kudos!!

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Angith_Nair
Continued Contributor
Continued Contributor

Hi @Anonymous ,

Try to use this code..

 

Column =
IF (
    ISBLANK ( Table[Sales-DATE] ),
    BLANK (),
    IF ( Table[Sales-DATE] <= DATE ( 2009, 12, 31 ), 0, Table[Year.Base] )
)

 

In place of "Table" write your table name.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.