É possível pegar um valor de um banco de dados e subtraí-lo do valor de outro banco de dados?

Hi Paulo,

The code of conduct for this forumcasj everyone too communicate in English.

Regarding your question, it is so broad and genetic that the  answer is yes, but that propably does not help you.

Regards,

Dsniel

Hi Paulo,

As you have been requested before, please write your questions in English.

The same way the community is here to help you by trying to provide you with pointers or answers to your questions, you can help the community (and yourself) by making sure everyone can understand you. Not everyone here speaks Portuguese, and you're missing out on knowledge from really great experts that cannot understand what you're asking. A little effort from you (online translating tools have shown to work pretty well with technical questions in the past), means you reach more people and that those people will be more willing to help you. Thanks!

As to whether it is possible to fetch a value from the database and subtract some other value also fetched from the database... the answer will be a definite "Yes, but..." we need to know more.

I'm not sure what you want here, can you provide more detail about your data-model and what is your goal with this operation? What Entities have the values you are interested in? Do those entities have a relationship between them? With just the info you provided, all we can come up with are very generic solutions:

  • if you just want to perform that calculation and use the value somewhere else (like display it on a Web Screen) it's as simple as:
    •  creating two separate Aggregates, each one will get one of the values
    •  then use an Assign node to store the subtraction in some variable.
    • Now that you have that new value you can do whatever you want with it:
      • display it on the screen
      • assign it to an attribute of an entity record and save it to the database again
      • return it as an output of an action
      • ...

 Hope this helps

Jorge Martins wrote:

Hi Paulo,

As you have been requested before, please write your questions in English.

The same way the community is here to help you by trying to provide you with pointers or answers to your questions, you can help the community (and yourself) by making sure everyone can understand you. Not everyone here speaks Portuguese, and you're missing out on knowledge from really great experts that cannot understand what you're asking. A little effort from you (online translating tools have shown to work pretty well with technical questions in the past), means you reach more people and that those people will be more willing to help you. Thanks!

As to whether it is possible to fetch a value from the database and subtract some other value also fetched from the database... the answer will be a definite "Yes, but..." we need to know more.

I'm not sure what you want here, can you provide more detail about your data-model and what is your goal with this operation? What Entities have the values you are interested in? Do those entities have a relationship between them? With just the info you provided, all we can come up with are very generic solutions:

  • if you just want to perform that calculation and use the value somewhere else (like display it on a Web Screen) it's as simple as:
    •  creating two separate Aggregates, each one will get one of the values
    •  then use an Assign node to store the subtraction in some variable.
    • Now that you have that new value you can do whatever you want with it:
      • display it on the screen
      • assign it to an attribute of an entity record and save it to the database again
      • return it as an output of an action
      • ...

 Hope this helps

I have 2 databases, with one variable VALUE in 1 and another variable other VALUE, I would like to take this subtract values!
 example:
I have a balance of 100 (this amount would be saved in 1 database),

And an expense of 50 (this amount saved in another database),

Take the value that is saved in the first database - the second (example 100-50 = 50) this total will be shown on the screen, I am created a mobile application.


That explanation is a lot better, thanks!

The approach I describe would work, but I'm going out on a limb here and assume you have:

  • Multiple Expenses that you want to factor in, not just one.
  • Each Expense will have a reference attribute to the Account they apply to

Given these assumptions:

  • Start by creating an Aggregate with Account as a Source.
  • Then open the aggregate and drag the Expense to it. This should automatically create a Join between the two tables, so that it matches Expenses and the Account they relate to.
  • Now you need to calculate the total Expense value per account:
    • Group By the attributes Account.Id and Account.Balance (at least, if you need to display other information for the account you may want to Group By those attributes as well)
    • Apply the Sum aggregate function to the Expense.Cost
  • Having the total Expense cost (in an aggregated attribute called CostSum) you want to obtain the balance left:
    • right-click on the CostSum attribute and choose Add Attribute to create a new calculated attribute
    • Call the new attribute FinalBalance
    • In the new attribute's formula you need to perform the subtraction, something along the lines of Balance - CostSum
  • In your screen, once the Aggregate is finished, you will have as part of its output the FinalBalance value you need to display

Hope this is clear enough

Jorge Martins wrote:

That explanation is a lot better, thanks!

The approach I describe would work, but I'm going out on a limb here and assume you have:

  • Multiple Expenses that you want to factor in, not just one.
  • Each Expense will have a reference attribute to the Account they apply to

Given these assumptions:

  • Start by creating an Aggregate with Account as a Source.
  • Then open the aggregate and drag the Expense to it. This should automatically create a Join between the two tables, so that it matches Expenses and the Account they relate to.
  • Now you need to calculate the total Expense value per account:
    • Group By the attributes Account.Id and Account.Balance (at least, if you need to display other information for the account you may want to Group By those attributes as well)
    • Apply the Sum aggregate function to the Expense.Cost
  • Having the total Expense cost (in an aggregated attribute called CostSum) you want to obtain the balance left:
    • right-click on the CostSum attribute and choose Add Attribute to create a new calculated attribute
    • Call the new attribute FinalBalance
    • In the new attribute's formula you need to perform the subtraction, something along the lines of Balance - CostSum
  • In your screen, once the Aggregate is finished, you will have as part of its output the FinalBalance value you need to display

Hope this is clear enough


In the picture sometimes it is clearer! I would like to take these marked values and make a subtraction!

Hi Paulo,

is there any relationship between the Expense records and the "gains" records?

You could potentially just do the same Sum for both kinds of movements (but in two separate aggregates like I initially described) and in the end subtract them in an Expression on screen.

They are on different screens, different databases, GAINS are on 1 database created, and EXPENSES on another database created!

Paulo Junior wrote:

Jorge Martins wrote:

That explanation is a lot better, thanks!

The approach I describe would work, but I'm going out on a limb here and assume you have:

  • Multiple Expenses that you want to factor in, not just one.
  • Each Expense will have a reference attribute to the Account they apply to

Given these assumptions:

  • Start by creating an Aggregate with Account as a Source.
  • Then open the aggregate and drag the Expense to it. This should automatically create a Join between the two tables, so that it matches Expenses and the Account they relate to.
  • Now you need to calculate the total Expense value per account:
    • Group By the attributes Account.Id and Account.Balance (at least, if you need to display other information for the account you may want to Group By those attributes as well)
    • Apply the Sum aggregate function to the Expense.Cost
  • Having the total Expense cost (in an aggregated attribute called CostSum) you want to obtain the balance left:
    • right-click on the CostSum attribute and choose Add Attribute to create a new calculated attribute
    • Call the new attribute FinalBalance
    • In the new attribute's formula you need to perform the subtraction, something along the lines of Balance - CostSum
  • In your screen, once the Aggregate is finished, you will have as part of its output the FinalBalance value you need to display

Hope this is clear enough


In the picture sometimes it is clearer! I would like to take these marked values and make a subtraction!


I think that's exactly it, could you send me an example of how to do it?


Hi Paulo,

Sorry, cannot provide a running example, but my instructions should be fairly simple to follow. I'll update them for what I understand is your scenario:

Assumptions:

  • Expense entity with Value attribute (represents money spent)
  • Income entity with Value attribute (represents money received)

You need to calculate the total income and the total expenses and then subtract the two:

  • In the Mobile Screen where you want to display the balance,
    • Start by creating an Aggregate, with Expense as a Source.
    • Now you need to calculate the total expenses:
      • Apply the Sum aggregate function to the Expense.Value
    • Then create another Aggregate, with Income as a Source.
    • Now you need to calculate the total income value:
      • Apply the Sum aggregate function to the Income.Value
    • Drag an Expression to your screen and set it's Value to
      GetIncomes.ValueSum - GetExpenses.ValueSum

At runtime, when you navigate to the screen the two Aggregates will start executing asynchronously to the rendering of the screen. Everytime one of the Aggregates finishes and returns data, the Expression will be refreshed (as it is using the data that changed), so by the time the second Aggregate finishes, your screen will be displaying the balance.

Hope these instructions are enough, but from your questions I get the feeling you would benefit much from going through the full online training on Developing OutSystems Mobile Apps. Give it a try, you won't regret it!