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

Announcements

No record found.

News and Announcements icon
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

  • Verified answer
    Martin Dráb Profile Picture
    240,827 Most Valuable Professional on at

    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

    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

    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
    240,827 Most Valuable Professional on at

    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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 495 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 432 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 366

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans