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

Notifications

Announcements

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 71
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
I have the same question (0)
  • Verified answer
    Vahid Ghafarpour Profile Picture
    12,202 Super User 2025 Season 2 on at
    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!
  • Gerardo Rentería García Profile Picture
    25,392 Most Valuable Professional on at

    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
    YUN ZHU Profile Picture
    95,930 Super User 2025 Season 2 on at
    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
     
     
     
  • Verified answer
    Teddy Herryanto (That NAV Guy) Profile Picture
    14,284 Super User 2025 Season 2 on at
    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.
  • LH-07011645-0 Profile Picture
    71 on at
    Thank you all for your quick responses! 
    You have saved me a lot of time.
     
    Best
    Louise

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

News and Announcements

Season of Giving Solutions is Here!

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,688

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 784 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 595 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans