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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
amlopez45
Frequent 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. 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. 
CustomerStatusReturn DateShipping DateDateDiff
AClosed1/28/20192/1/20194
BActive2/4/2019 4
CActive  4
DActive2/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. 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @amlopez45,

 

Can you please share pbix file for test? Your formula works well on my side.

 

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

HI @amlopez45,

 

Can you please share pbix file for test? Your formula works well on my side.

 

Regards,
Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hi @v-shex-msft,

 

The formula is working well now. I tried Collins method and it seemed to do the job. Not really sure what happened. Thank you for offering to help. Smiley Happy

amlopez45
Frequent 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. 
CustomerStatusReturn DateShipping DateDateDiff
AClosed1/28/20192/1/20194
BActive2/4/2019 4
CActive  4
DActive2/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. 

Anonymous
Not applicable

hello @amlopez45

 

first things first, try changing your data format (top of modeling tab) to date for your calculated column and see if that fixes your issue

 

here is a picture of what I did.

dateeeeeeeeeeeee.PNG

best regards,

Collin

Hello @Anonymous,

 

Thank you for the suggestion, the formula is working well now. Smiley Happy

Anonymous
Not applicable

@amlopez45

 

Great to hear, be sure to mark the post as the solution for anyone else that comes along. 

 

best Regards,

Collin

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.