web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / If statement in a Form
Power Apps
Answered

If statement in a Form

(0) ShareShare
ReportReport
Posted on by 340

Can anyone help please.

 

I have a form and in that form I have a toggle that toggles on a date picker. If the toggle is off, I'd like it to send the number 21 to SharePoint , if the toggle is on, I'd like it to send the datepicker selected date. There are 2 columns in SharePoint

Could anyone help please? Thank you

Categories:
  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Not sure if I'm understanding correctly - a number and a date are 2 different things to SP. What is your column type that you want to right to?

    You could set the default of the form field to a variable, then in the OnChange property of the DatePicker have it put the selected date into that variable. The problem is that the variable can only be one type - either a number or a date. Or do you mean that one of the columns in the SP list will hold the 21 and the other the date?

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    @pricey79 

    In the Update property of the card containing the toggle, If(Toggle.Value,DatePicker.SelectedDate,21)

  • pricey79 Profile Picture
    340 on at

    @BrianS  thank you for your reply. Sorry, one column is a single line of text and one is a date.

    So yes you are correct, if its the date, put it in the date column, if not, put it in the text column

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    In that case you could put an If in the Update property of the Toggle 

    If(Self.Value,"",21) 

    and then have the Date Picker right to the SP list normally. I would add a default to the Date Picker of Today() in an if statement - If(Toggle.Value, Today()) - that way it will not have a value unless the Toggle makes it visible

  • pricey79 Profile Picture
    340 on at

    @BrianS thank you. I'll give it a go

    How would the form know what column it is updating though as the card is assigned to a column I think?

    Apologies if i'm not explaining this very well

     

    There is a data card called Datedays. In that card there is a toggle. That toggle affects the visible property of a datepicker which appears in the datacard when the toggle is on.

    Have I explained that well enough?

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Each Field on the form is assigned to a field in the data source, so you would assign the toggle to the text field and the date picker to the to the date field. The reason you don't want to set the default on the date picker all the time is because it will right that default even if it is not visible. If you don't give it a value it will not write one.

  • pricey79 Profile Picture
    340 on at

    @BrianS Thank you for your replies. 

    I'm still a bit confused though , sorry

    When you say Field , do you mean datacard?

  • BrianS Profile Picture
    2,407 Super User 2024 Season 1 on at

    Sorry - yes the datacard is assigned to a field in the datasource by the Datefield property. The Update property is the value that will be written to that field when the Form is Submitted

  • pricey79 Profile Picture
    340 on at

    @BrianS Thank you

    So if I understand you correctly. I should have 2 different datacards. One that updates the text, and one that updates the date?

    I only want one of them to be submitted though. Either the date if its chosen, or the text 21 if no date is chosen

     

    Thank you for your time so far

  • Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    In the text datacard Update property:

    If(!Toggle.Value, 21, Blank())

    in the date datacard Update property: 

    If(Toggle.Value, DatePicker.SelectedDate, Blank())

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 239

Last 30 days Overall leaderboard