Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

problem creating dynamic query in DAX4

Posted on by 593

Hi

I want to create a query  in a class, using dialog values.

The query should basically represent the following SQL-Statement: (plus some other restricting values for custTable if selected)

while SELECT * FROM CustTable
        JOIN SUM(InvoiceAmount) FROM CustInvoiceJour
            GROUP BY InvoiceAccount
            WHERE CustTable.AccountNum == CustInvoiceJour .InvoiceAccount
            && ((CustInvoiceJour .InvoiceDate >= fromDate && CustInvoiceJour .InvoiceDate<=toDate))

My code for query looks like this

    QueryBuildDatasource    qbdsCustomers, qbdsInvoiceJour;
    Query                   query = new Query();
    ;

    qbdsCustomers       = query.addDataSource(tablenum(CustTable));
    SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, AccountNum)).value(custAccount == "" ? SysQuery::valueUnlimited() : custAccount);
    SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, LineDisc)).value(lineDiscCode == "" ? SysQuery::valueUnlimited() : lineDiscCode);
    if (blockedActive)
        SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, Blocked)).value(queryValue(custBlocked));
    SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, CountryRegionId)).value(country);
    SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, EndDisc)).value(endDiscCode == "" ? SysQuery::valueUnlimited() : endDiscCode);
    SysQuery::findOrCreateRange(qbdsCustomers, fieldnum(CustTable, MOCTotalVolume)).value(totalVolume == 0 ? SysQuery::valueUnlimited() : queryValue(totalVolume));

    if( !(fromDate == datenull() && toDate == datenull()) )
    {
        qbdsInvoiceJour     = qbdsCustomers.addDataSource(tablenum(CustInvoiceJour));
        qbdsInvoiceJour.orderMode(OrderMode::GroupBy);
        qbdsInvoiceJour.relations(false);
        qbdsInvoiceJour.addLink(fieldnum(CustTable,AccountNum), fieldnum(CustInvoiceJour,InvoiceAccount));
        qbdsInvoiceJour.addSelectionField(fieldNum(CustInvoiceJour,InvoiceAmount),SelectionField::Sum);
        qbdsInvoiceJour.addSortField(fieldnum(CustInvoiceJour,InvoiceAccount));
        SysQuery::findOrCreateRange(qbdsInvoiceJour, fieldnum(CustInvoiceJour, InvoiceAccount)).value(custAccount == "" ? SysQuery::valueUnlimited() : custAccount);
        SysQuery::findOrCreateRange(qbdsInvoiceJour, fieldnum(CustInvoiceJour, InvoiceDate)).value(queryrange(fromDate, toDate));
    }

The query does not find any customers but there should be

  • CRSW Profile Picture
    CRSW 593 on at
    RE: problem creating dynamic query in DAX4

    Any ideas?

  • CRSW Profile Picture
    CRSW 593 on at
    RE: problem creating dynamic query in DAX4

    To me qbdsCustomers Statement look like it should but Queryrun returns no accountnumber

  • CRSW Profile Picture
    CRSW 593 on at
    RE: problem creating dynamic query in DAX4

    the qbds objects contain following statements:

    qbdsCustomers

    SELECT * FROM CustTable JOIN SUM(InvoiceAmount) FROM CustInvoiceJour GROUP BY CustInvoiceJour.InvoiceAccount ASC WHERE CustTable.AccountNum = CustInvoiceJour.InvoiceAccount AND ((InvoiceDate>={ts '2019-10-01 00:00:00.000'} AND InvoiceDate<={ts '2019-10-17 00:00:00.000'}))

    qbdsInvoiceJour

    SELECT SUM(InvoiceAmount) FROM CustInvoiceJour GROUP BY CustInvoiceJour.InvoiceAccount ASC WHERE CustTable.AccountNum = CustInvoiceJour.InvoiceAccount AND ((InvoiceDate>={ts '2019-10-01 00:00:00.000'} AND InvoiceDate<={ts '2019-10-17 00:00:00.000'}))

  • CRSW Profile Picture
    CRSW 593 on at
    RE: problem creating dynamic query in DAX4

    NOthing....an object id not more

  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: problem creating dynamic query in DAX4

    If you print the actual query statement to infolog with query.toString() what do you see? That's the first step in the investigation - understanding what the current query does.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans