cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
JamesM
Helper V
Helper V

Unsure how to check if a value is empty and use an IF statement on that condition.

I obtain a date time from a connector. 

 

 

Set(heartBeatDateTime,InSiteConnector.GetStoreHeartBeat({rowlimit:1,server:selectedServer,ordercol:"RowInsertDateTime",order:"DESC"}))

 

I then do a DATEDIFF to check how old - in hours - that date time is from now

 

 

Set(hoursDifference, DateDiff(Now(),First(heartBeatDateTime).LastHeardFrom))

 

I then want do do a check to say if that value is blank (hoursDifference) then force it to be 99. 

 

 

If(IsBlank(hoursDifference),hoursDifference=99,hoursDifference)

 

However this isn't working. hoursDifferene remains blank/empty (I am using a label to output the value to debug)

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @JamesM,

 

For your first question, do you want to reset the hoursDifference variable?

If you want to reset the hoursDifference variable, I think there is something wrong with the formula that you provided. If you want to reset the hoursDifference variable when the hoursDifference variable is blank, please modify your formula as below (Set the OnSelect property of a Button control to following):

If(
IsBlank(hoursDifference),
Set(hoursDifference,99)
)

In addition, if you want to do a DATEDIFF to check how old in hours, I think there is something wrong with the formula that you provided. Please modify your formula as below:

Set(
hoursDifference,
DateDiff(Now(),First(heartBeatDateTime).LastHeardFrom,Hours)
)

For your second question, please modify your formula as below:

If(
loadInSiteCheck=true && hoursDifference < 1,
"Checking last poll date from InSite",
"InSite last polled @ "
)

More details about the DateDiff function and If function within PowerApps, please check the following article:

DateDiff function

If function

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
JamesM
Helper V
Helper V

I have solved this by doing the IF isBlank within the image control instead (the idea being if the value is blank show a 'X' if it's not, show a tick) however I have come up against another issue. 


How do I create a logical operation of IF, AND.. 

 

e.g. (If a value is TRUE, and a number is less than 1, show text 1, otherwise show text 2). 

 

I tried this, but no luck

 

If (loadInSiteCheck && hoursDifference < 1,"Checking last poll date from InSite","InSite last polled @ ", "")

 

 

Hi @JamesM

 

Here are a couple of comments. In answer to your first question, you might want to consider the Coalesce function. This function evaluates its arguments in order and returns the first non blank value. Here's an example of its simple usage.

Coalesce(hoursDifference, 99)

Here's the syntax that you would use to reset your hoursDifference variable.

 

Set(hoursDifference, 
    Coalesce(hoursDifference, 99)
)

In answer to your second question, I think the problem might be because you're passing 4 arguments to the If function. With this type of usage, argument 3 will be a second condition that PowerApps tests if the first condition resolves to false.  Perhaps you might have more success with something like this..

 

If (loadInSiteCheck && hoursDifference < 1,
    "Checking last poll date from InSite",
    "InSite last polled @ " & Text(First(heartBeatDateTime).LastHeardFrom)
)

 

 

 

v-xida-msft
Community Support
Community Support

Hi @JamesM,

 

For your first question, do you want to reset the hoursDifference variable?

If you want to reset the hoursDifference variable, I think there is something wrong with the formula that you provided. If you want to reset the hoursDifference variable when the hoursDifference variable is blank, please modify your formula as below (Set the OnSelect property of a Button control to following):

If(
IsBlank(hoursDifference),
Set(hoursDifference,99)
)

In addition, if you want to do a DATEDIFF to check how old in hours, I think there is something wrong with the formula that you provided. Please modify your formula as below:

Set(
hoursDifference,
DateDiff(Now(),First(heartBeatDateTime).LastHeardFrom,Hours)
)

For your second question, please modify your formula as below:

If(
loadInSiteCheck=true && hoursDifference < 1,
"Checking last poll date from InSite",
"InSite last polled @ "
)

More details about the DateDiff function and If function within PowerApps, please check the following article:

DateDiff function

If function

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power Apps Community Call Jan. 2022 768x460.png

Power Apps Community Call

Please join us on Wednesday, January 19th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Top Solution Authors
Top Kudoed Authors
Users online (1,260)