Forum Discussion
amlopez45
7 years agoFrequent Visitor
Incorrect output for IF function
Hi Everyone, I am not sure what is going on with the IF function but it is not working as I would expected to. I want to get the number of days between two dates if a certain condition is met. I...
- Anonymous7 years ago
HI amlopez45,
Can you please share pbix file for test? Your formula works well on my side.
Regards,
Xiaoxin Sheng
amlopez45
7 years agoFrequent Visitor
Hi Everyone,
I am not sure what is going on with the IF function but it is not working as I would expected to. I want to get the number of days between two dates if a certain condition is met. If the condition is not met I want it get me the number of days that have passed.
This is my current formula.
DateDiff = IF('Table'[Status] = "Closed", DATEDIFF('Table'[Return Date].[Date], 'Table' [Shipping Date].[Date], DAY), DATEDIFF('Table'[Return Date].[Date], TODAY(), DAY))
For example, when I add the DateDiff column that contains the formula above it outputs 4 for every row.
| Customer | Status | Return Date | Shipping Date | DateDiff |
| A | Closed | 1/28/2019 | 2/1/2019 | 4 |
| B | Active | 2/4/2019 | 4 | |
| C | Active | 4 | ||
| D | Active | 2/4/2019 | 4 |
How do I get it to output the correct value?
Note: When I take out the IF function and seperate the DATEDIFF functions the output is correct.