Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Answered

IF in query object

(1) ShareShare
ReportReport
Posted on by 67
Hello colleagues
 
Is it possible in a Query to use something like IF with data item link?
 
For example
To make a query which takes out Item Ledger Entries from T32 for the last week,
 
IF source type = Customer Then DataItemLink Source No to Customer Name in Table 18 Customers
IF source type = Vendor Then DataItemLink to Source No Vendor Name in Table 23 Vendors
 
It seems to me that this is not the way a query works, but maybe others can suggest something else which can achieve this
 
Thanks Louise
  • LH-07011645-0 Profile Picture
    67 on at
    IF in query object
    Thank you all for your quick responses! 
    You have saved me a lot of time.
     
    Best
    Louise
  • Verified answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    13,137 Moderator on at
    IF in query object
    Query does not support conditional statement.
     
    Your option is:
    - Create 2 queries
    - Create 1 query without the customer or vendor name. when you use the query in code, you add a code to go and fetch the customer or vendor name based on the source no.
  • Verified answer
    YUN ZHU Profile Picture
    78,989 Super User 2025 Season 1 on at
    IF in query object
    This is different from TableRelation, where you cannot set an IF(<Conditions>. And you cannot create two DataItems at the same level in Query.
    So the only way is to create two different queries as VaHiX mentioned.
     
    Thanks.
    ZHU
     
     
     
  • gdrenteria Profile Picture
    15,612 Most Valuable Professional on at
    IF in query object

    Hi, good day
    I hope this can help you, and give you some hints.

    Data Item Links - Business Central | Microsoft Learn

    Best Regards
    Gerardo

  • Verified answer
    VaHiX Profile Picture
    5,646 Super User 2025 Season 1 on at
    IF in query object
    I'd create two separate queries, one for customer-related entries and another for vendor-related entries and use a codeunit or a page to run both queries and combine the results based on the source type!

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,025 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,852 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans