<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Paginated Reports selecting dataset &amp;quot;An item with the same key has already been added.&amp;quot; SQL Union..? in Report Server</title>
    <link>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009388#M35629</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="765679" data-lia-user-login="EdgeExtension35" class="lia-mention lia-mention-user"&gt;EdgeExtension35&lt;/a&gt; , small change in datepart for datatype, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try now&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT &lt;BR /&gt;E.ID, &lt;BR /&gt;E.EstimateNumber,&lt;BR /&gt;E.divisionNumber,&lt;BR /&gt;E.deptNumber,&lt;BR /&gt;E.JobName, &lt;BR /&gt;E.JobLocationCity, &lt;BR /&gt;E.JobLocationState,&lt;BR /&gt;E.EstimateDateDue, &lt;BR /&gt;E.EstimateTimeDue, &lt;BR /&gt;E.ExtendedDate, &lt;BR /&gt;E.EstimateNotes,&lt;BR /&gt;E.OutstandingDate, &lt;BR /&gt;E.GCorCMorOwner, &lt;BR /&gt;E.NameOfGCorCMorO, &lt;BR /&gt;IIF(E.EstimateDateDue&amp;lt;E.ExtendedDate,E.ExtendedDate,E.EstimateDateDue) AS DateDue,&lt;BR /&gt;IIF(LEN(DATEPART(HH,E.EstimateTimeDue))&amp;lt;2,CONCAT('0',CAST(DATEPART(HH,E.EstimateTimeDue) AS VARCHAR)),CAST(DATEPART(HH,E.EstimateTimeDue) AS VARCHAR)) AS HourDue,&lt;BR /&gt;DATEPART(N,E.EstimateTimeDue) AS MinuteDue,&lt;BR /&gt;E.JobWorkType, &lt;BR /&gt;E.ServiceCommercial, &lt;BR /&gt;E.BidBond, &lt;BR /&gt;E.SiteVisit, &lt;BR /&gt;E.WageType, &lt;BR /&gt;CONCAT(TRIM(Estimators.EstimatorFirstName),' ', LEFT(Estimators.EstimatorLastName,1), '.') AS EstimatorNm, &lt;BR /&gt;E.BudgetEstimate,&lt;BR /&gt;STUFF((SELECT ', ' + RS.[SystemType]&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS SystemTypes,&lt;BR /&gt;STUFF((SELECT ', ' + CAST(RS.[Price] AS VARCHAR)&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS Prices,&lt;BR /&gt;STUFF((SELECT ', ' + R.[RoofSystemDesc]&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;INNER JOIN [dbo].[RoofSystems] R ON RS.[RoofSysID] = R.[ID]&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS RoofSystems,&lt;BR /&gt;NULL AS EndDate, --Adding column to accommodate any scheduled event's ending dates from the SchedEvents table.&lt;BR /&gt;E.EstimateNotes,&lt;BR /&gt;NULL AS eventType, --eventType&lt;BR /&gt;NULL AS who --who&lt;BR /&gt;FROM &lt;BR /&gt;Estimates E &lt;BR /&gt;LEFT JOIN Estimators ON Estimators.EstimatorID = E.EstimatorID&lt;BR /&gt;WHERE &lt;BR /&gt;(LEFT(E.EstimateNumber,1)='E') &lt;BR /&gt;AND E.RemoveFromSchedule = 0 &lt;BR /&gt;AND (&lt;BR /&gt;(((E.WonLost) Not In ('W','L'))) &lt;BR /&gt;OR ((E.WonLost) Is Null) &lt;BR /&gt;OR (((E.WonLost) In ('W','L')) AND ((E.KeepOnEstSchedule)=1))&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;UNION ALL&lt;/P&gt;
&lt;P&gt;-- Selecting all records from SchedEvents table&lt;BR /&gt;SELECT &lt;BR /&gt;S.ID,&lt;BR /&gt;S.estimateNum AS EstimateNumber,&lt;BR /&gt;S.divisionNumber,&lt;BR /&gt;S.deptNumber AS deptNumber, -- Corrected deptumber to deptNumber&lt;BR /&gt;S.eventType AS JobName, -- JobName&lt;BR /&gt;NULL AS JobLocationCity,&lt;BR /&gt;NULL AS JobLocationState,&lt;BR /&gt;S.startDate AS EstimateDateDue, -- EstimateDateDue&lt;BR /&gt;S.eventTime AS EstimateTimeDue, -- EstimateTimeDue&lt;BR /&gt;NULL AS ExtendedDate,&lt;BR /&gt;NULL AS EstimateNotes,&lt;BR /&gt;NULL AS OutstandingDate,&lt;BR /&gt;NULL AS GCorCMorOwner,&lt;BR /&gt;NULL AS NameOfGCorCMorO,&lt;BR /&gt;S.startDate AS DateDue, -- DateDue&lt;BR /&gt;NULL AS HourDue,&lt;BR /&gt;NULL AS MinuteDue,&lt;BR /&gt;NULL AS JobWorkType,&lt;BR /&gt;NULL AS ServiceCommercial,&lt;BR /&gt;NULL AS BidBond,&lt;BR /&gt;NULL AS SiteVisit,&lt;BR /&gt;NULL AS WageType,&lt;BR /&gt;NULL AS EstimatorNm,&lt;BR /&gt;NULL AS BudgetEstimate,&lt;BR /&gt;NULL AS SystemTypes,&lt;BR /&gt;NULL AS Prices,&lt;BR /&gt;NULL AS RoofSystems,&lt;BR /&gt;CASE &lt;BR /&gt;WHEN S.startDate = S.endDate THEN NULL&lt;BR /&gt;ELSE S.endDate&lt;BR /&gt;END AS EndDate,&lt;BR /&gt;NULL AS EstimateNotes,&lt;BR /&gt;S.eventType,&lt;BR /&gt;S.who&lt;BR /&gt;FROM &lt;BR /&gt;SchedEvents S;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2024 15:14:11 GMT</pubDate>
    <dc:creator>amitchandak</dc:creator>
    <dc:date>2024-06-25T15:14:11Z</dc:date>
    <item>
      <title>Paginated Reports selecting dataset "An item with the same key has already been added." SQL Union..?</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009344#M35626</link>
      <description>&lt;P&gt;I'm building a report in PowerBI paginated reports, fed by a dataset that that is tied to a SQL stored procedure. Everything was working fine, until I modified the SP to include a UNION to another table. The query runs fine in SSMS and I get the intended results, however when I try to validate the procedure in Report Builder I get the error:&lt;BR /&gt;"&lt;STRONG&gt;&lt;EM&gt;Could not create a list of fields for the query. Verify that you can connect to the data source and that your query syntax is correct.&lt;/EM&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;EM&gt;An item with the same key has already been added.&lt;/EM&gt;&lt;/STRONG&gt;"&lt;BR /&gt;&lt;BR /&gt;I've tried creating a new blank report, readding my Datasource and trying to add the dataset again with the same results. I've looked over the SP and I cannot for the life of me figure out why it would be throwing that error, however all of the obscure posts &amp;amp; whatnot I've found in my research seem to suggest this happens on a table join/merge, so more than likely it's something with how PowerBI is handling the UNION portion of my query. Any thoughts? Im attaching a slightly scrubbed version of my SP query below:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT 
E.ID, 
E.EstimateNumber,
E.divisionNumber,
E.deptNumber,
E.JobName, 
E.JobLocationCity, 
E.JobLocationState,
E.EstimateDateDue, 
E.EstimateTimeDue, 
E.ExtendedDate, 
E.EstimateNotes,
E.OutstandingDate, 
E.GCorCMorOwner, 
E.NameOfGCorCMorO, 
IIF(E.EstimateDateDue&amp;lt;E.ExtendedDate,E.ExtendedDate,E.EstimateDateDue) AS DateDue,
IIF(LEN(DATEPART(HH,EstimateTimeDue))&amp;lt;2,CONCAT('0',STR(DATEPART(HH,EstimateTimeDue))),STR(DATEPART(HH,EstimateTimeDue))) AS HourDue,
DATEPART(N,EstimateTimeDue) AS MinuteDue,
E.JobWorkType, 
E.ServiceCommercial, 
E.BidBond, 
E.SiteVisit, 
E.WageType, 
CONCAT(TRIM(Estimators.EstimatorFirstName),' ', LEFT(Estimators.EstimatorLastName,1), '.') AS EstimatorNm, 
E.BudgetEstimate,
STUFF((SELECT ', ' + RS.[SystemType]
        FROM [dbo].[EstRoofSystems] RS
        WHERE RS.[EstimateID] = E.[ID]
        FOR XML PATH('')), 1, 2, '') AS SystemTypes,
STUFF((SELECT ', ' + CAST(RS.[Price] AS VARCHAR)
        FROM [dbo].[EstRoofSystems] RS
        WHERE RS.[EstimateID] = E.[ID]
        FOR XML PATH('')), 1, 2, '') AS Prices,
STUFF((SELECT ', ' + R.[RoofSystemDesc]
          FROM [dbo].[EstRoofSystems] RS
          INNER JOIN [dbo].[RoofSystems] R ON RS.[RoofSysID] = R.[ID]
          WHERE RS.[EstimateID] = E.[ID]
          FOR XML PATH('')), 1, 2, '') AS RoofSystems,
NULL AS EndDate, --Adding column to accommodate any scheduled event's ending dates from the SchedEvents table.
E.EstimateNotes,
NULL AS eventType, --eventType
NULL AS who --who

FROM 
Estimates E 
LEFT JOIN Estimators ON Estimators.EstimatorID = E.EstimatorID

WHERE 
(LEFT(E.EstimateNumber,1)='E') AND E.RemoveFromSchedule = 0 AND ((((E.WonLost) Not In ('W','L'))) OR (((E.WonLost) Is Null)) OR (((E.WonLost) In ('W','L')) AND ((E.KeepOnEstSchedule)=1)))

UNION ALL

-- Selecting all records from SchedEvents table
SELECT 
S.ID,
S.estimateNum,
S.divisionNumber,
S.deptumber,
S.eventType, -- JobName
NULL, -- JobLocationCity
NULL, -- JobLocationState
S.startDate, -- EstimateDateDue
S.eventTime, -- EstimateTimeDue
NULL, -- ExtendedDate
NULL, -- EstimateNotes
NULL, -- OutstandingDate
NULL, -- GCorCMorOwner
NULL, -- NameOfGCorCMorO
S.startDate, -- DateDue
NULL, -- HourDue
NULL, -- MinuteDue
NULL, -- JobWorkType
NULL, -- ServiceCommercial
NULL, -- BidBond
NULL, -- SiteVisit
NULL, -- WageType
NULL, -- EstimatorNm
NULL, -- BudgetEstimate
NULL, -- SystemTypes
NULL, -- Prices
NULL, -- RoofSystems
CASE 
        WHEN S.startDate = S.endDate THEN NULL
        ELSE S.endDate
    END AS EndingDate,
NULL, -- EstimateNotes
S.eventType,
S.who

FROM 
SchedEvents S;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 14:45:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009344#M35626</guid>
      <dc:creator>EdgeExtension35</dc:creator>
      <dc:date>2024-06-25T14:45:06Z</dc:date>
    </item>
    <item>
      <title>Re: Paginated Reports selecting dataset "An item with the same key has already been added." SQL Union..?</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009388#M35629</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="765679" data-lia-user-login="EdgeExtension35" class="lia-mention lia-mention-user"&gt;EdgeExtension35&lt;/a&gt; , small change in datepart for datatype, &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try now&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SELECT &lt;BR /&gt;E.ID, &lt;BR /&gt;E.EstimateNumber,&lt;BR /&gt;E.divisionNumber,&lt;BR /&gt;E.deptNumber,&lt;BR /&gt;E.JobName, &lt;BR /&gt;E.JobLocationCity, &lt;BR /&gt;E.JobLocationState,&lt;BR /&gt;E.EstimateDateDue, &lt;BR /&gt;E.EstimateTimeDue, &lt;BR /&gt;E.ExtendedDate, &lt;BR /&gt;E.EstimateNotes,&lt;BR /&gt;E.OutstandingDate, &lt;BR /&gt;E.GCorCMorOwner, &lt;BR /&gt;E.NameOfGCorCMorO, &lt;BR /&gt;IIF(E.EstimateDateDue&amp;lt;E.ExtendedDate,E.ExtendedDate,E.EstimateDateDue) AS DateDue,&lt;BR /&gt;IIF(LEN(DATEPART(HH,E.EstimateTimeDue))&amp;lt;2,CONCAT('0',CAST(DATEPART(HH,E.EstimateTimeDue) AS VARCHAR)),CAST(DATEPART(HH,E.EstimateTimeDue) AS VARCHAR)) AS HourDue,&lt;BR /&gt;DATEPART(N,E.EstimateTimeDue) AS MinuteDue,&lt;BR /&gt;E.JobWorkType, &lt;BR /&gt;E.ServiceCommercial, &lt;BR /&gt;E.BidBond, &lt;BR /&gt;E.SiteVisit, &lt;BR /&gt;E.WageType, &lt;BR /&gt;CONCAT(TRIM(Estimators.EstimatorFirstName),' ', LEFT(Estimators.EstimatorLastName,1), '.') AS EstimatorNm, &lt;BR /&gt;E.BudgetEstimate,&lt;BR /&gt;STUFF((SELECT ', ' + RS.[SystemType]&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS SystemTypes,&lt;BR /&gt;STUFF((SELECT ', ' + CAST(RS.[Price] AS VARCHAR)&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS Prices,&lt;BR /&gt;STUFF((SELECT ', ' + R.[RoofSystemDesc]&lt;BR /&gt;FROM [dbo].[EstRoofSystems] RS&lt;BR /&gt;INNER JOIN [dbo].[RoofSystems] R ON RS.[RoofSysID] = R.[ID]&lt;BR /&gt;WHERE RS.[EstimateID] = E.[ID]&lt;BR /&gt;FOR XML PATH('')), 1, 2, '') AS RoofSystems,&lt;BR /&gt;NULL AS EndDate, --Adding column to accommodate any scheduled event's ending dates from the SchedEvents table.&lt;BR /&gt;E.EstimateNotes,&lt;BR /&gt;NULL AS eventType, --eventType&lt;BR /&gt;NULL AS who --who&lt;BR /&gt;FROM &lt;BR /&gt;Estimates E &lt;BR /&gt;LEFT JOIN Estimators ON Estimators.EstimatorID = E.EstimatorID&lt;BR /&gt;WHERE &lt;BR /&gt;(LEFT(E.EstimateNumber,1)='E') &lt;BR /&gt;AND E.RemoveFromSchedule = 0 &lt;BR /&gt;AND (&lt;BR /&gt;(((E.WonLost) Not In ('W','L'))) &lt;BR /&gt;OR ((E.WonLost) Is Null) &lt;BR /&gt;OR (((E.WonLost) In ('W','L')) AND ((E.KeepOnEstSchedule)=1))&lt;BR /&gt;)&lt;/P&gt;
&lt;P&gt;UNION ALL&lt;/P&gt;
&lt;P&gt;-- Selecting all records from SchedEvents table&lt;BR /&gt;SELECT &lt;BR /&gt;S.ID,&lt;BR /&gt;S.estimateNum AS EstimateNumber,&lt;BR /&gt;S.divisionNumber,&lt;BR /&gt;S.deptNumber AS deptNumber, -- Corrected deptumber to deptNumber&lt;BR /&gt;S.eventType AS JobName, -- JobName&lt;BR /&gt;NULL AS JobLocationCity,&lt;BR /&gt;NULL AS JobLocationState,&lt;BR /&gt;S.startDate AS EstimateDateDue, -- EstimateDateDue&lt;BR /&gt;S.eventTime AS EstimateTimeDue, -- EstimateTimeDue&lt;BR /&gt;NULL AS ExtendedDate,&lt;BR /&gt;NULL AS EstimateNotes,&lt;BR /&gt;NULL AS OutstandingDate,&lt;BR /&gt;NULL AS GCorCMorOwner,&lt;BR /&gt;NULL AS NameOfGCorCMorO,&lt;BR /&gt;S.startDate AS DateDue, -- DateDue&lt;BR /&gt;NULL AS HourDue,&lt;BR /&gt;NULL AS MinuteDue,&lt;BR /&gt;NULL AS JobWorkType,&lt;BR /&gt;NULL AS ServiceCommercial,&lt;BR /&gt;NULL AS BidBond,&lt;BR /&gt;NULL AS SiteVisit,&lt;BR /&gt;NULL AS WageType,&lt;BR /&gt;NULL AS EstimatorNm,&lt;BR /&gt;NULL AS BudgetEstimate,&lt;BR /&gt;NULL AS SystemTypes,&lt;BR /&gt;NULL AS Prices,&lt;BR /&gt;NULL AS RoofSystems,&lt;BR /&gt;CASE &lt;BR /&gt;WHEN S.startDate = S.endDate THEN NULL&lt;BR /&gt;ELSE S.endDate&lt;BR /&gt;END AS EndDate,&lt;BR /&gt;NULL AS EstimateNotes,&lt;BR /&gt;S.eventType,&lt;BR /&gt;S.who&lt;BR /&gt;FROM &lt;BR /&gt;SchedEvents S;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 15:14:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009388#M35629</guid>
      <dc:creator>amitchandak</dc:creator>
      <dc:date>2024-06-25T15:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Paginated Reports selecting dataset "An item with the same key has already been added." SQL Union..?</title>
      <link>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009642#M35634</link>
      <description>&lt;P&gt;I'm still getting the same error message about the duplicate item key, unfortunately.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 17:46:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Report-Server/Paginated-Reports-selecting-dataset-quot-An-item-with-the-same/m-p/4009642#M35634</guid>
      <dc:creator>EdgeExtension35</dc:creator>
      <dc:date>2024-06-25T17:46:31Z</dc:date>
    </item>
  </channel>
</rss>

