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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Sum function with assetID from AssetTrans table

(0) ShareShare
ReportReport
Posted on by

Hi All,

I need to write select statement for summing the AmountMST value based on AssetID, 

Data is like from AssetTrans Table:

AssetId

AmountMST

AS001

10

AS001

20

AS002

30

AS002

20

Result should be :

AS001 – 30    // sum of AS001 (10+20)

AS002 – 50    // sum of AS002 (30+20)

I am able to get the sum value based on asset Id but in the result only sum value is displaying not the asset id.

select statement is:

select sum(AmountMST),AssetId from assetTrans
where assetTrans.AssetId == "AS001";

info(strFmt('%1,%2',assetTrans.AmountMST,assetTrans.AssetId));

Output is 30, (not displaying the assetid)

Please advice how can i get the sum value and assetid number in the output.

Regards,

Akbar

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,879 Most Valuable Professional on at
    RE: Sum function with assetID from AssetTrans table - D365FO

    You neither aggregate nor group by AssetId, therefore its doesn't have any value defined.

    This is an example with groupping:

    select sum(AmountMST), AssetId from assetTrans
    	group by AssetId
    	where assetTrans.AssetId == "AS001";

    And this one with an aggregation:

    select sum(AmountMST), maxOf(AssetId) from assetTrans
    	where assetTrans.AssetId == "AS001";

    By the way, please use Insert > Code (in the rich formatting view) to paste source code.

  • Akbarpasha Profile Picture
    on at
    RE: Sum function with assetID from AssetTrans table - D365FO

    Thank you very much Martin , i am able to get the desired output now.

    Sure i will use rich formatting view from next time onwards.

    Thanks again, it helped me a lot.

  • waytod365 Profile Picture
    351 on at
    RE: Sum function with assetID from AssetTrans table - D365FO

    Hi Martin sir,

    AssetId is string it's won't return maxOf value am i right? Correct me if I'm wrong.

    Thanks 

  • Martin Dráb Profile Picture
    236,879 Most Valuable Professional on at
    RE: Sum function with assetID from AssetTrans table

    The easiest thing, and the best for learning, is trying it. :-)

    Then you can question your assumption that strings can't be sorted.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 683 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 620

#3
Martin Dráb Profile Picture

Martin Dráb 563 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans