cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
cooltechie
Level: Powered On

Sum of different fields values

Hi,

 

I have field 1, field 2, field 3 and I would like to set field 4 = field 1 + field 2 + field 3

 

How do I set this in Power Apps?


Accepted Solutions
samuelJ
Level 8

Re: Sum of different fields values

Please clarify "field"? A field is not one of the control or text types.  I will assume you have either a label or a text input.  The text property of these are read as strings and not numbers (values).  I am also assuming your "field 4" is a label.

Set the text property of the label you want to be the sum to:

Value(label1.text) + Value(label2.text)

If the assumptions are wrong, please provide more information.  

 

Microsoft Employee

Re: Sum of different fields values

You could use SharePoint calculated fields or you could use my example above and replace the test source with your SharePoint source and adjust the field names accordingly. By "Field" I mean the column name. For example, in the following record: {a:1, b:2} the field names are "a" and "b" and the record field values are correspondingly 1 and 2

All Replies
Microsoft Employee

Re: Sum of different fields values

Hello @cooltechie,

I prepared a small demo for solving this:

1. Create an empty app

2. Add an empty vertical gallery control (Gallery1) and a button control (Button1)

3. Button1.OnSelect=ClearCollect(cc, {a:1, b:11}, {a:2, b:12}, {a:3, b:13}, {a:4, b:14})  
    *This means select the Button1 control, find its "OnSelect" property and paste ClearCollect(cc, {a:1, b:11}, {a:2, b:12}, {a:3, b:13}, {a:4, b:14}) into it.

4. Add 3 Label controls into your Gallery (Label1, Label2 and Label3). Note that those controls should be added inside your gallery, not on screen level.

5. Set Gallery1.Items=AddColumns(cc, "Sum", Sum(a, b))

6. Set Label1.Text=ThisItem.a
    Label2.Text=ThisItem.b
    Label3.Text=ThisItem.Sum

7. Preview the app and click on the button.

samuelJ
Level 8

Re: Sum of different fields values

Please clarify "field"? A field is not one of the control or text types.  I will assume you have either a label or a text input.  The text property of these are read as strings and not numbers (values).  I am also assuming your "field 4" is a label.

Set the text property of the label you want to be the sum to:

Value(label1.text) + Value(label2.text)

If the assumptions are wrong, please provide more information.  

 

cooltechie
Level: Powered On

Re: Sum of different fields values

Actually I am using SharePoint list field values. May be I should use a calculated field to sum the total

Microsoft Employee

Re: Sum of different fields values

You could use SharePoint calculated fields or you could use my example above and replace the test source with your SharePoint source and adjust the field names accordingly. By "Field" I mean the column name. For example, in the following record: {a:1, b:2} the field names are "a" and "b" and the record field values are correspondingly 1 and 2