cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ACPBSCi
Resolver I
Resolver I

Using a Variable in an If Statement

Upon creation of a record, I set a global variable called "varRecord". By using this and a ".________", I can utilize all the values in all the fields of the record. For example, varRecord.'Account Name' or varRecord.'Launch Date'

I want to hide a button if the program type equals "ABC Program", but I can't figure out the expression. This expression does not work:

If(equals(VarRecord.'ProgramType'("ABC Program"),true),false, true)

I feel like I'm close. What am I missing?

1 ACCEPTED SOLUTION

Accepted Solutions
StormEAnderson
Resolver I
Resolver I

It may be because 'Program Type' is a choice field, in which case you are not dealing with a string but a record. If that is the case you would need to use the "Value" property within that record. So try either of the following:

// If the field is a choice / lookup field
Not(VarRecord.'ProgramType'.Value = "ABC Program")
// --- evaluates to FALSE when programType is equal to "ABC Program"

// If the field is a text field
Not(VarRecord.'ProgramType' = "ABC Program")

 

View solution in original post

4 REPLIES 4
Pstork1
Dual Super User III
Dual Super User III

Try the following in the Visible property of the button.

If(equals(VarRecord.'ProgramType',"ABC Program"),false, true)

 



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

No, that's not working either.

I wish the "get help for this error" feature was actually helpful. All it says is that the "If" has some invalid arguments. You think?

Your recommendation makes sense. The syntax makes sense. Is there something different I need to do because of the type of global variable I'm using and the way I'm using it (varRecord.'Program Type')? Am I not able to use it this way?

StormEAnderson
Resolver I
Resolver I

It may be because 'Program Type' is a choice field, in which case you are not dealing with a string but a record. If that is the case you would need to use the "Value" property within that record. So try either of the following:

// If the field is a choice / lookup field
Not(VarRecord.'ProgramType'.Value = "ABC Program")
// --- evaluates to FALSE when programType is equal to "ABC Program"

// If the field is a text field
Not(VarRecord.'ProgramType' = "ABC Program")

 

View solution in original post

GOT IT!

Not(VarRecord.'Program Type' = "ABC Program")

There is a space in "Program Type". Gotta use those suggestions when they pop up. You can't trust that you know exactly how it appears.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,892)