Forum Discussion
"if" function in Power Query not working properly
Pascal_Werner I would add a column first that returns todays date when the completion date is blank/empty or the completion date when it exists. Then use that column in stead of the [#"Completed"] column to calculate duration.
The step to add such a column, that you could call 'CutOffDate', would be:
Format this column as 'Date'.
You'll find a very small working example that brings you through the stage of adding the CutOffDate and calculate a duration, in the attached workbook. See if you can get it to work with this approach. Come back here if you don't. And then, please clarify the issue by attaching a file with some example date (non confidential) or a link that gives access to the file, stored on OneDrive or some similar file-sharing site, and mention the expected outcome.
- mickhenceJun 05, 2024Copper ContributorIf the "if" function in Power Query is not working properly, ensure your syntax is correct. The basic structure is:
powerquery
Copy code
if [condition] then [result1] else [result2]
Common issues include missing "else" statements or incorrect comparisons (e.g., using "=" instead of "=="). Double-check your syntax and conditions.- Riny_van_EekelenJun 05, 2024Platinum Contributor
mickhence Sorry, but I don't know what you mean. I know how 'if' works in PQ.
- SergeiBaklanJun 05, 2024MVP
As a comment, "doesn't work properly" means the statement returns some result, but not one which we expect. If syntax is wrong, statement doesn't work at all.