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
lc1
Helper III
Helper III

If Statement

Hello,

I need to create the following formula in DAX:

excel:

if (column 1="C", column 5-column 7, "Open"

PBI:

Response Time = IF(sr[source]="c", calculate (sr[receiveddate]-sr[closingdate]),"Open"))

 

Please advise how to do it, I tried many different ways but I keep getting a syntax error (invalid token, line 1, offset 30, 'sr[receiveddate]-sr[closingdate]),"Open")))))

1 ACCEPTED SOLUTION

@lc1 can you try follownig, I'm shooting in dark without looking at data model. 

 

Response Time = IF(sr[source]="c", 
DATEDIFF(sr[receiveddate],sr[closingdate], DAY))

Make sure to add as a column? And I assume datatype for both receivedate and closingdate is date.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

8 REPLIES 8
parry2k
Super User
Super User

@lc1 try this

 

Response Time = IF(sr[source]="c", 
DATEDIFF(sr[receiveddate],sr[closingdate], DAY),
"Open")


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I get this error:

 

A single value for column 'receiveddate' in table 'sr' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

@lc1 Are you adding this as a measure or column? The dax I proposed suppose to be a column.

 

And you might run into another error, we are returning number but in else condition we are returning text, but let's see if we have add this expression as a column. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

It was as a calculated column, but I used the same formula adding a column and it gives me #ERROR

@lc1 can you try follownig, I'm shooting in dark without looking at data model. 

 

Response Time = IF(sr[source]="c", 
DATEDIFF(sr[receiveddate],sr[closingdate], DAY))

Make sure to add as a column? And I assume datatype for both receivedate and closingdate is date.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Sorry, I accepted the answer but I'm missing the last part of the condition:

like if it is "C", substract Received Date from Closed Day, else, "Open"

 

 

 

 

@lc1 try this

 

Response Time = IF(sr[source]="c", 
FORMAT(DATEDIFF(sr[receiveddate],sr[closingdate], DAY), "####" ),
"Open")


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you very much, it worked.

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.