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 :
Microsoft Dynamics AX (Archived)

X++ query - trouble splitting up summed up amount

(0) ShareShare
ReportReport
Posted on by 145

Hello,
The query on the bottom gives me the following result :

A1201~710~2015~12~~~~~~~01~~~~~~~016~001~423418.44~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~114214.80~
A1201~710~2015~12~~~~~~~01~~~~~~~016~022~9954.60~
A1201~710~2015~12~~~~~~~01~~~~~~~016~030~170156.88~
A1201~710~2015~12~~~~~~~01~~~~~~~016~031~4892.04~


As you can see , this sums the value for each cost center :
I want to see each value seperately like this :

A1201~710~2015~12~~~~~~~11~~~~~~~014~~647770.71~

A1201~710~2015~12~~~~~~~01~~~~~~~016~~102148.68~
A1201~710~2015~12~~~~~~~01~~~~~~~016~001~423418.44~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~41431.32~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~2333.04~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~21491.64~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~25184.28~
A1201~710~2015~12~~~~~~~01~~~~~~~016~020~23774.52~
A1201~710~2015~12~~~~~~~01~~~~~~~016~022~3228.00~
A1201~710~2015~12~~~~~~~01~~~~~~~016~022~6726.60~
A1201~710~2015~12~~~~~~~01~~~~~~~016~030~75939.12~
-------------------------------------------------------
private Query baseQuery_AssetTrans()
{
    Query                   q = new Query();
    QueryBuildDataSource    qbds, qbdsAssetBook, qbdsAssetTrans;
    QueryBuildRange         qbr;

    DimensionProvider       dimensionProvider;
    Name                    costCenterDimName;

    //-- AssetTable --//
    qbds = q.addDataSource(tableNum(AssetTable));

    // filter on majorType -> not empty
    qbr = qbds.addRange(fieldNum(AssetTable, MajorType));
    qbr.value(SysQuery::valueNotEmptyString());
    //qbds.addGroupByField(fieldNum(AssetTable, MajorType));

    //-- AssetBook --//
    qbdsAssetBook = qbds.addDataSource(tableNum(AssetBook));
    qbdsAssetBook.relations(true);

    // acquisition must be in this year or earlier
    qbr = qbdsAssetBook.addRange(fieldNum(AssetBook, AcquisitionDate));
    qbr.value(strFmt('(%1.%2 <= %3)'
                    , qbdsAssetBook.name()
                    , fieldStr(AssetBook, AcquisitionDate)
                    , date2StrXpp(toDate)));

    // exclude no depreciation
    qbr = qbdsAssetBook.addRange(fieldNum(AssetBook, Depreciation));
    qbr.value(queryValue(NoYes::Yes));

    //-- AssetTrans --//
    qbdsAssetTrans = qbdsAssetBook.addDataSource(tableNum(AssetTrans));
    qbdsAssetTrans.relations(true);
    qbdsAssetTrans.addSelectionField(fieldNum(AssetTrans, AmountMST), SelectionField::Sum);
        
    
    //-- Group by cost center --//
    dimensionProvider = new DimensionProvider();
    costCenterDimName = DimensionAttribute::find(RDSFinancialDimensionMapping::getAttributeRecIdForFinDimension(RDSFinancialDimensionValues::CostCenter)).Name;
    qbds = dimensionProvider.addDataSourceToQuery(q, qbdsAssetTrans.name(), fieldStr(assetTrans, DefaultDimension), DimensionComponent::DimensionAttribute, costCenterDimName);
    qbds.addGroupByField(fieldNum(DimensionAttributeValueSetItemView, DisplayValue));
    
    return q;
}



I tried commenting the group by's and the sum but i still can't get a decent result.

What am i missing here?


*This post is locked for comments

I have the same question (0)
  • Vilmos Kintera Profile Picture
    46,149 on at

    Can you please edit your post and re-paste the code with Rich formatting editor's Insert code tag </> for better readability (to align them with correct tabbing)?

  • Jeffrey Saelen Profile Picture
    145 on at
    
                          
  • Suggested answer
    István Orosz Profile Picture
    2,137 on at

    Hi,

    I tried to convert it into T-SQL, and this is what I got (although I'm not pretty sure about the left outer join and some other points, sorry):

    SELECT SUM(AmountMST) FROM AssetTrans
    JOIN AssetBook ON AssetBook.BookId = AssetTrans.BookId AND AssetBook.AssetId = AssetTrans.AssetId 
    JOIN AssetTable ON AssetTable.ASSETID = AssetBook.AssetId
    LEFT OUTER JOIN DimensionAttributeValueSetItemView ON AssetTrans.DefaultDimension = DimensionAttributeValueSetItemView.DimensionAttributeValueSet AND ((DimensionAttribute = 5637145327))
    WHERE AssetBook.AcquisitionDate <= 12/10/2017 AND AssetBook.Depreciation = 1 AND  AssetTable.MajorType <> ''
    GROUP BY AssetTable.MajorType, DimensionAttributeValueSetItemView.DisplayValue 

    and it seems to me that the leaving the SUM solves the problem.

    Regards,

    István

  • Verified answer
    Jeffrey Saelen Profile Picture
    145 on at

    Thanks for answering and trying to reproduce

    I found the error... the query is OK and my solution worked ( leaving out the sum and such )

    the problem was that in the base class of this class there was a method which groups everything again....

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#3
GL-01081504-0 Profile Picture

GL-01081504-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans