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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to set a where condition between two fields of a same table in AOT query

(0) ShareShare
ReportReport
Posted on by

Hi,

I have an SQL as below, 

select CUS.INVOICE,CUS.AMOUNTCUR from dbo.CUSTTRANS CUS 
	where CUS.AMOUNTCUR > 0 
	  AND CUS.AMOUNTCUR <> CUS.SETTLEAMOUNTCUR

I'm trying to convert this to AOT query and I'm having trouble in setting a where condition between two fields of the same table.

Test-Query1.pngTest-Query2.png

The TSQL for the AOT query is as below,

SELECT AmountCur, Invoice FROM CustTrans(CustTrans_1) 
	WHERE ((AmountCur>0)) 
	AND ((NOT (SettleAmountCur = 0)))
The results between SQL and DAX AOT Query don't match.
The problem here is with CUS.AMOUNTCUR <> CUS.SETTLEAMOUNTCUR.
How can I set this in the AOT query.
Please help.

Thanks,
Praveen.


*This post is locked for comments

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,162 Moderator on at

    Please see this article: docs.microsoft.com/.../using-expressions-in-query-ranges

    You might need to set the range in code instead of the AOT query definition.

  • Community Member Profile Picture
    on at

    Thanks Nikolaos, I was able to solve my issue through the website you posted.

        QueryBuildDataSource        qbr1;
        QueryRun                    qrrun;
        Query   qr = new Query(queryStr(TestQuery));
        
        qbr1 = qr.dataSourceTable(tablenum(CustTrans));
        qbr1.addSortField(fieldNum(CustTrans,Invoice),SortOrder::Descending);
        qbr1.name("CustTrans");
        qbr1.addRange(fieldNum(CustTrans, Invoice)).value(
            strFmt('((%1.%2 != %1.%3))',
                qbr1.name(),
                fieldStr(CustTrans, AmountCur),
                fieldStr(CustTrans, SettleAmountCur)));
        
        info(qr.toString());

    The above code changes to the AOT query gives me the following TSQL which is exactly what I was looking for.

    SELECT AccountNum, AmountCur, Invoice FROM CustTrans(CustTrans) ORDER BY CustTrans.Invoice DESC WHERE ((AmountCur>0)) AND ((((CustTrans.AmountCur != CustTrans.SettleAmountCur))))


    Thank you.

    Praveen.

  • nmaenpaa Profile Picture
    101,162 Moderator on at

    Great to hear that! Please mark the helpful answer(s) as verified so that others can benefit from them. Thanks!

  • YokTH Profile Picture
    5 on at


    //this.query().datasourceTable(TableNum(CustTrans)).addRange(FieldNum(CustTrans,recid)).value(strFmt('(%1 - %2 > 0)', fieldStr(custtrans, amountcur),fieldStr(custtrans, settleamountcur) ) );


    this.query().datasourceTable(TableNum(CustTrans)).addRange(FieldNum(CustTrans,recid)).value(strFmt('((%1 != %2))',fieldStr(CustTrans, AmountCur),fieldStr(CustTrans, SettleAmountCur)));

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans