Excel Query if

th081

Board Regular
Joined
Mar 26, 2006
Messages
98
Office Version
  1. 365
Platform
  1. Windows
Hello,

This is probably a basic question but i cant seem to get it. It is my first foray into Power Query in Excel.

I have imported a table in Power Query, the table has a Date_Time column and a STAT column the STAT column has a 1 or 0. The 1 represents a start time and the 0 the end time.

I have inserted a conditional column and wrote a if : if [STAT] = 0 then [Date_Time] else if [STAT] = 1 then null else null

expecting to see the end time from the Date_Time column however it says Binary and when i try to convert it to a date time format it says error.

I am basically trying to get the end time into the same line as the start time and then delete all the rows with 0 (the end time) from the data set.

Can anyone help.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
if [STAT] = 0 then [Date_Time] else null
Power Query:
= Table.AddColumn(Source, "IF", each if [STAT] = 0 then [Date_Time] else null)
 
Upvote 0
this is what i have at the moment:

= Table.AddColumn(#"Renamed Columns1", "Custom.1", each if[STAT]= 0 then [DATE_TIME] else null)

if i change to: = Table.AddColumn(#"Renamed Columns1", "Custom.1", "IF", each if[STAT]= 0 then [DATE_TIME] else null)

it throws an error

Expression.Error: We cannot convert the value "IF" to type Function.
Details:
Value=IF
Type=Type
 
Upvote 0
of course it's error
wrong = Table.AddColumn(#"Renamed Columns1", "Custom.1", "IF", each if[STAT]= 0 then [DATE_TIME] else null)
Power Query:
= Table.AddColumn(#"Renamed Columns1", "IF", each if [STAT] = 0 then [DATE_TIME] else null)

use Add Column - Conditional Column then
acc.png
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,606
Messages
6,120,490
Members
448,967
Latest member
visheshkotha

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