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 :
Finance | Project Operations, Human Resources, ...
Answered

Refresh Entity Store error : Subquery returned more than 1 value.

(0) ShareShare
ReportReport
Posted on by 903

Hi guys,

When I run Refresh Entity Store, I have following error :

"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression."

Unfortunately, it doesnt say on which query. How to trace that ? Because it is also a custom Entity, and obviously it has many tables and query, I just need some idea where to start to check ?

Any help will be appreciated.

Thanks,

I have the same question (0)
  • Tony zhong Profile Picture
    903 on at

    Hi,

    Regarding this Refresh Entity Store, with new user interface, can we  know the underlying process by means like transaction log that we can look  for?

    Anyway the point is, if there is an error, where is the place we should go and start tracing what's happening ?

    Current log in Refresh Entity Store, named "Event message" are really not helping.

    Capture13.GIF

    Thanks,

  • Crispin John Augustine Profile Picture
    37,081 on at

    The part you have hidden from the message "Data populate failed for ****" is your Aggregate measurement.

    You have to go into each measure group's datasource, and get to the underlying query. You should eventually encounter one query which is responsible.

    Start only for the measure group datasources first. If it still leaves you in the dark, proceed with the dimension datasources as well.

  • Tony zhong Profile Picture
    903 on at

    Hi Crispin,

    Thank you, as you said, eventually I did found the "culprit". If you (or anyone else) don't mind, I would like to ask some advise for what is wrong with my query .

    So, it turned, I have this query :

    SELECT T1.SALESID

    ,

    (CAST

     (

       (ISNULL

            (

              (

          SELECT 1

          FROM   CASETABLE a,

                        SALESTABLE b

          WHERE  a.projid = b.projid

          AND    a.dataareaid = b.dataareaid

          AND    b.salesid = T1.salesid

                ), 0

             )

         ) AS int

       )

    ) AS invoiceorigin

    FROM DEVICEINVOICEFACT T1

    The one in red is the cause of error, and according to one website, I should put MAX in that subquery of "SELECT 1" 

    Can someone explain to me why ? Is it because the key T1.SALESID on the string  ( " ..... AND b.salesid = T1.salesid....." ) ?

    The T1.SALESID does have possibility of occurring more than 1, but if I test it with WHERE clause to put the SALESID which occurred more than 1 like this :

    SELECT T1.SALESID

    ,

    (CAST

     (

       (ISNULL

            (

              (

          SELECT 1

          FROM   CASETABLE a,

                        SALESTABLE b

          WHERE  a.projid = b.projid

          AND    a.dataareaid = b.dataareaid

          AND    b.salesid = T1.salesid

                ), 0

             )

         ) AS int

       )

    ) AS invoiceorigin

    FROM DEVICEINVOICEFACT T1 Where T1.SALESID = '000408" (which indeed that salesid in T1 table have more than 1 rows), the query does execute completely with no error. 

    So basically I need to change my query to be like this :

    SELECT T1.SALESID

    ,

    (CAST

     (

       (ISNULL

            (

              (

          SELECT MAX(1)

          FROM   CASETABLE a,

                        SALESTABLE b

          WHERE  a.projid = b.projid

          AND    a.dataareaid = b.dataareaid

          AND    b.salesid = T1.salesid

                ), 0

             )

         ) AS int

       )

    ) AS invoiceorigin

    FROM DEVICEINVOICEFACT T1

    Just want to understand why we need that MAX()

    Kindly advice.

    Thanks

  • Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Tony,

    Subquery in the field list section should return 1 value or nothing (null). In your case max function will aggregate data to one record if there are more than 1 record returned by select criteria. It should be similar to (select top 1 1 from ...).

  • Tony zhong Profile Picture
    903 on at

    Hi Sergei,

    Thank you. Understand about MAX will aggregate data to one record. Just for curiosity, can I know which record is really causing this ? I mean how to know it ?

    Because as mentioned, I tried to use the SALESID that have multiple row, and put it in WHERE clause, the query is ran, it only give me duplicates, which is expected. So basically the value that causing the error is not the one that I choose as a test.

    So basically I want to know how to solve this by looking at the actual rows, so it can be "backup" in the business process it self, probably we need to change the logic of my entry system, not only by fixing the query.

    Thanks in advance.

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Tony,

    You can try to replace max(1) with count(1) and if invoiceOrigin field contains value bigger than 1 - there are duplicates

    select * from
    (
    SELECT T1.SALESID
    
    ,
    
    (CAST
    
     (
    
       (ISNULL
    
            (
    
              (
    
          SELECT COUNT(1)
    
          FROM   CASETABLE a,
    
                        SALESTABLE b
    
          WHERE  a.projid = b.projid
    
          AND    a.dataareaid = b.dataareaid
    
          AND    b.salesid = T1.salesid
    
                ), 0
    
             )
    
         ) AS int
    
       )
    
    ) AS invoiceorigin
    
    FROM DEVICEINVOICEFACT T1
    ) t
    where t.invoiceorigin > 1

  • Tony zhong Profile Picture
    903 on at

    Hi Sergei,

    Thanks, now I can see.

    Appreciate your advise.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 616

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 460 Super User 2026 Season 1

#3
Syed Haris Shah Profile Picture

Syed Haris Shah 331 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans