<?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 Dynamic M Query against Azure SQL Database - Direct Query in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2566641#M36587</link>
    <description>&lt;P&gt;I'm creating a PBI report that utilizes Direct Query, and we want it to return one record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been using the article&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-dynamic-m-query-parameters" target="_blank" rel="noopener"&gt;Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Docs&lt;/A&gt;&amp;nbsp;for reference, and have my query updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WorkOrderID is a parameter created in Manage Parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let   
    selectedworkorder = Text.Combine ({"'", Number.ToText(WorkOrderID), "'"}),
    dynamicfilter = Text.Combine({" where dm.workorderid = ",  selectedworkorder}),
    
    reportquery = "
           Select DM.Division, DM.Foreman, DM.Customer, J.PONumber, DM.JobName, DM.Yard, DM.WorkDate, weekend.Date AS WeekEndDate, DM.WorkStart, DM.LunchStart, DM.LunchEnd, DM.WorkEnd, DM.InvoiceProperty1Label, DM.InvoiceProperty1Value, DM.InvoiceProperty2Label,  DM.InvoiceProperty2Value, DM.InvoiceProperty3Label, DM.InvoiceProperty3Value, DM.InvoiceProperty4Label, DM.InvoiceProperty4Value, DM.InvoiceProperty5Label, DM.InvoiceProperty5Value, DM.BillableType, DM.WorkActivity, DM.MasterTimesheetID,           DM.WorkOrderID          from dbo.WorkOrderDataMart DM         join dbo.DimJob J on DM.JobID = J.JobID          join dbo.FactTimesheet t on DM.WorkOrderID = T.TimesheetID         join dbo.DimDate weekend on t.WeekEndDateID = weekend.DateKey ",

    FinalQuery = Text.Combine({reportquery, dynamicfilter}),

    Source = Sql.Database("proeazuretest.database.windows.net", "WJC", FinalQuery)  
    
in
    Source&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I'm getting the below error.&amp;nbsp; &amp;nbsp;When I pull out the query itself and run against our DB, it works fine.&amp;nbsp; &amp;nbsp;I'm wondering if I have a syntax error, or if someone has encountered this, and found a resolution?&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Expression.Error: We cannot convert the value "&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Select ..." to type Record.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Details:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Value=&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Select DM.Division, DM.Foreman, DM.Customer, J.PONumber, DM.JobName, DM.Yard, DM.WorkDate, weekend.Date AS WeekEndDate, DM.WorkStart, DM.LunchStart, DM.LunchEnd, DM.WorkEnd, DM.InvoiceProperty1Label, DM.InvoiceProperty1Value, DM.InvoiceProperty2Label, DM.InvoiceProperty2Value, DM.InvoiceProperty3Label, DM.InvoiceProperty3Value, DM.InvoiceProperty4Label, DM.InvoiceProperty4Value, DM.InvoiceProperty5Label, DM.InvoiceProperty5Value, DM.BillableType, DM.WorkActivity, DM.MasterTimesheetID, DM.WorkOrderID from dbo.WorkOrderDataMart DM join dbo.DimJob J on DM.JobID = J.JobID join dbo.FactTimesheet t on DM.WorkOrderID = T.TimesheetID join dbo.DimDate weekend on t.WeekEndDateID = weekend.DateKey where dm.workorderid = '32253'&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Type=[Type]&lt;/EM&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jun 2022 13:00:50 GMT</pubDate>
    <dc:creator>ALMalecha</dc:creator>
    <dc:date>2022-06-08T13:00:50Z</dc:date>
    <item>
      <title>Dynamic M Query against Azure SQL Database - Direct Query</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2566641#M36587</link>
      <description>&lt;P&gt;I'm creating a PBI report that utilizes Direct Query, and we want it to return one record.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been using the article&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-dynamic-m-query-parameters" target="_blank" rel="noopener"&gt;Dynamic M query parameters in Power BI Desktop - Power BI | Microsoft Docs&lt;/A&gt;&amp;nbsp;for reference, and have my query updated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WorkOrderID is a parameter created in Manage Parameters.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let   
    selectedworkorder = Text.Combine ({"'", Number.ToText(WorkOrderID), "'"}),
    dynamicfilter = Text.Combine({" where dm.workorderid = ",  selectedworkorder}),
    
    reportquery = "
           Select DM.Division, DM.Foreman, DM.Customer, J.PONumber, DM.JobName, DM.Yard, DM.WorkDate, weekend.Date AS WeekEndDate, DM.WorkStart, DM.LunchStart, DM.LunchEnd, DM.WorkEnd, DM.InvoiceProperty1Label, DM.InvoiceProperty1Value, DM.InvoiceProperty2Label,  DM.InvoiceProperty2Value, DM.InvoiceProperty3Label, DM.InvoiceProperty3Value, DM.InvoiceProperty4Label, DM.InvoiceProperty4Value, DM.InvoiceProperty5Label, DM.InvoiceProperty5Value, DM.BillableType, DM.WorkActivity, DM.MasterTimesheetID,           DM.WorkOrderID          from dbo.WorkOrderDataMart DM         join dbo.DimJob J on DM.JobID = J.JobID          join dbo.FactTimesheet t on DM.WorkOrderID = T.TimesheetID         join dbo.DimDate weekend on t.WeekEndDateID = weekend.DateKey ",

    FinalQuery = Text.Combine({reportquery, dynamicfilter}),

    Source = Sql.Database("proeazuretest.database.windows.net", "WJC", FinalQuery)  
    
in
    Source&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I'm getting the below error.&amp;nbsp; &amp;nbsp;When I pull out the query itself and run against our DB, it works fine.&amp;nbsp; &amp;nbsp;I'm wondering if I have a syntax error, or if someone has encountered this, and found a resolution?&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Expression.Error: We cannot convert the value "&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Select ..." to type Record.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Details:&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Value=&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Select DM.Division, DM.Foreman, DM.Customer, J.PONumber, DM.JobName, DM.Yard, DM.WorkDate, weekend.Date AS WeekEndDate, DM.WorkStart, DM.LunchStart, DM.LunchEnd, DM.WorkEnd, DM.InvoiceProperty1Label, DM.InvoiceProperty1Value, DM.InvoiceProperty2Label, DM.InvoiceProperty2Value, DM.InvoiceProperty3Label, DM.InvoiceProperty3Value, DM.InvoiceProperty4Label, DM.InvoiceProperty4Value, DM.InvoiceProperty5Label, DM.InvoiceProperty5Value, DM.BillableType, DM.WorkActivity, DM.MasterTimesheetID, DM.WorkOrderID from dbo.WorkOrderDataMart DM join dbo.DimJob J on DM.JobID = J.JobID join dbo.FactTimesheet t on DM.WorkOrderID = T.TimesheetID join dbo.DimDate weekend on t.WeekEndDateID = weekend.DateKey where dm.workorderid = '32253'&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;Type=[Type]&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 13:00:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2566641#M36587</guid>
      <dc:creator>ALMalecha</dc:creator>
      <dc:date>2022-06-08T13:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic M Query against Azure SQL Database - Direct Query</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2566668#M36588</link>
      <description>&lt;P&gt;Figured it out - it was a syntax error:&lt;/P&gt;&lt;P&gt;The source statement should have been:&amp;nbsp;&amp;nbsp;Source = Sql.Database("proeazuretest.database.windows.net", "WJC", &lt;STRONG&gt;[Query=FinalQuery]&lt;/STRONG&gt;)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;let   
    selectedworkorder = Text.Combine ({"'", Number.ToText(WorkOrderID), "'"}),
    dynamicfilter = Text.Combine({" where dm.workorderid = ",  selectedworkorder}),
    
    reportquery = " Select DM.Division, DM.Foreman, DM.Customer, J.PONumber, DM.JobName, DM.Yard, DM.WorkDate, weekend.Date AS WeekEndDate, DM.WorkStart, DM.LunchStart, DM.LunchEnd, DM.WorkEnd, DM.InvoiceProperty1Label, DM.InvoiceProperty1Value, DM.InvoiceProperty2Label,  DM.InvoiceProperty2Value, DM.InvoiceProperty3Label, DM.InvoiceProperty3Value, DM.InvoiceProperty4Label, DM.InvoiceProperty4Value, DM.InvoiceProperty5Label, DM.InvoiceProperty5Value, DM.BillableType, DM.WorkActivity, DM.MasterTimesheetID, DM.WorkOrderID from dbo.WorkOrderDataMart DM  join dbo.DimJob J on DM.JobID = J.JobID  join dbo.FactTimesheet t on DM.WorkOrderID = T.TimesheetID join dbo.DimDate weekend on t.WeekEndDateID = weekend.DateKey",

    FinalQuery = Text.Combine({reportquery, dynamicfilter}),

    Source = Sql.Database("proeazuretest.database.windows.net", "WJC", [Query=FinalQuery])  
    
in
    Source&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jun 2022 13:14:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2566668#M36588</guid>
      <dc:creator>ALMalecha</dc:creator>
      <dc:date>2022-06-08T13:14:46Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic M Query against Azure SQL Database - Direct Query</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2574055#M36653</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/372750"&gt;@ALMalecha&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am glad that you can figure out your problem. Please kindly accept your workaround as the solution. More people who with similar problems will benefit from it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;BR /&gt;Rico Zhou&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jun 2022 06:37:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Dynamic-M-Query-against-Azure-SQL-Database-Direct-Query/m-p/2574055#M36653</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-06-13T06:37:20Z</dc:date>
    </item>
  </channel>
</rss>

