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 / Subtraction of two col...
Power Apps
Answered

Subtraction of two columns in powerapps Gallery

(0) ShareShare
ReportReport
Posted on by 60

Hello,

 

I am new to PowerApps. Appreciate if someone call help me with my query. I am trying to subtract two columns in a gallery.

 

Subtract (Current SMU - Last Change Out Hours) from the same gallery(Gallery2_7) and put that value under Current Component hours.

 

Gallery Items = FirstN(SortByColumns(Filter('Component Tracking', StartsWith('AssetID',AssetIDPassed_2.Text)),"Created",SortOrder.Descending),60)

 

May I know the formula that i should use for subtracting this two columns. Thank you for your help!

 

Navishamun11_0-1713815672377.png

 

Categories:
  • Verified answer
    Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Navishamun11 - please try the below:

     

    FirstN(
     SortByColumns(
     Filter(
     AddColumns(
     'Component Tracking',
     _Result,
     ('Current SMU' - 'Last Change Out Hours')
     ),
     Len(AssetIDPassed_2.Text) = 0 || StartsWith(
     AssetID,
     AssetIDPassed_2.Text
     )
     ),
     "Created",
     SortOrder.Descending
     ),
     60
    )

     

    Then apply the below onto the Text property of your Label:

     

    ThisItem._Result

     

    However, it is worth noting that the FirstN and the AddColumns functions are not delegable. You can mitigate this somewhat by using the With function to separate the delegable functions (like Filter and SortByColumns) from the rest of the code, and then apply the non-delegable functions (FirstN, AddColumns) on that delegable subset.

     

    With(
     {
     _prefiltered_data: SortByColumns(
     Filter(
     'Component Tracking',
     Len(AssetIDPassed_2.Text) = 0 || StartsWith(
     AssetID,
     AssetIDPassed_2.Text
     )
     ),
     "Created",
     SortOrder.Descending
     )
     },
     FirstN(
     AddColumns(
     _prefiltered_data,
     _Result,
     ('Current SMU' - 'Last Change Out Hours')
     ),
     60
     )
    )

     

  • Navishamun11 Profile Picture
    60 on at

    Hello Amik,

     

    Firstly thank you for your reply. I tried your solution but I still get errors.

     

    My Gallery (Gallery2_7) is connected to a SharePoint list 'Component Tracking' from where I get the columns I need. 

     

    Navishamun11_0-1713821894504.png

     

    ('Current SMU' - 'ast Change Out Hours') Should be ('Unit Current Hrs' - 'Last Change Out Hours'). 

     

    Appreciate your help here. thanks!

     

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Navishamun11 - you're selecting a Control called "AssetID" in your formula, when what you should be doing is selecting the Asset ID field in your data source (samre as your original code):

     

    Amik_0-1713833176520.png

  • Navishamun11 Profile Picture
    60 on at

    Hello Amik,

     

    Thank you again for your reply.

     

    Navishamun11_0-1713883555726.png

    Component Tracking Sharepoint List shows 'Asset ID' I tried the same still some error. It says expected text value If i hover over the Asset ID.

    Navishamun11_1-1713883635997.png

     

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Navishamun11 -

     

    1. Please could you take a screenshot of that error message
    2. Is the Asset ID field a Single Line Text data type?
  • Navishamun11 Profile Picture
    60 on at

    Hello Amik,

     

    Here you go,

     

    Navishamun11_0-1713884668408.png

    2. Yes, you are right.

     

    Thank you AMik

  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Navishamun11 - are you applying this formula into the Items property of your Gallery control?

  • Navishamun11 Profile Picture
    60 on at

    Hello Amik,

     

    No, not there. I put this formula under Text property of Current Component hours. See screenshot below. Thank you.

     

    Navishamun11_0-1713886034664.png

     

    Regards,

    Naveen

  • Verified answer
    Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @Navishamun11 - please apply the formula to the Items property of your Gallery and follow the rest of my instructions.

  • Navishamun11 Profile Picture
    60 on at

    Hello Amik. 

     

    It worked like Magic. Thank you so much for your help.

     

    I have two more columns with calculated fields. How to add multiple calculated columns in the below formula. Would repeating the below formula work?

     

    FirstN( AddColumns( _prefiltered_data, _Result, ('Current SMU' - 'Last Change Out Hours') ), 60 )

     

    Hrs Until Due = Bench - _Result('Current SMU' - 'Last Change Out Hours')

    % of Life Remainder = Hrs Until due/Component Life

    Navishamun11_0-1713985515039.png

    With(
     {
     _prefiltered_data: SortByColumns(
     Filter(
     'Component Tracking',
     Len(AssetIDPassed_2.Text) = 0 || StartsWith(
     AssetID,
     AssetIDPassed_2.Text
     )
     ),
     "Created",
     SortOrder.Descending
     )
     },
     FirstN(
     AddColumns(
     _prefiltered_data,
     _Result,
     ('Current SMU' - 'Last Change Out Hours')
     ),
     60
     )
    )

     

    Navishamun11_1-1713991140170.png

     

    Regards,

    Naveen

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 224 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 189 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 126

Last 30 days Overall leaderboard