Power Query - If statement to return date

KasperSSI

New Member
Joined
Nov 28, 2019
Messages
26
Office Version
  1. 365
Platform
  1. Windows
Hi,

I want my if statment to return a date from a date column. However it returns Error. format of the date column dd-mm-yyyy.

I tried
if [Movement] = "opening or "counting" then "" else [date]

any one has a solution for this?
 

Attachments

  • 1733742469635.png
    1733742469635.png
    14.3 KB · Views: 7

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try with or [movement]=“counting”
 
Upvote 0
Further to Jim's comment:
1) Date.ToText is only going to work if you have applied a Changed Type step and made sure the Date column data type is Date
2) Your formula as Jim mentioned should look like this:
Power Query:
if ([Movement] = "opening" or [Movement] = "counting") then "" else Date.ToText([Date])

3) Although in Excel your only option is to insert "" in Power Query you could have used "null" (without the quotes).
This leaves the cell blank rather than having it filled with an empty string.

PS: Do you really want the resulting Date to be a Text String ? That is bound to cause you issues later on.
 
Upvote 0
Solution
Further to Jim's comment:
1) Date.ToText is only going to work if you have applied a Changed Type step and made sure the Date column data type is Date
2) Your formula as Jim mentioned should look like this:
Power Query:
if ([Movement] = "opening" or [Movement] = "counting") then "" else Date.ToText([Date])

3) Although in Excel your only option is to insert "" in Power Query you could have used "null" (without the quotes).
This leaves the cell blank rather than having it filled with an empty string.

PS: Do you really want the resulting Date to be a Text String ? That is bound to cause you issues later on.
Thanks for the help. It worked - Also found a solution via. Conditional column.
 
Upvote 0

Forum statistics

Threads
1,224,979
Messages
6,182,126
Members
453,090
Latest member
boonga

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top