title: Importing data using temp tables in Power BI
body: <p>I have the following SQL query I want to use to import data into Power BI. It involves the creation of a temp table and using that table as the main data source. How can I do this in Power BI? I tried using this query in the editor when loading data from a database, but I keep getting an error like so
  <a href="https://i.stack.imgur.com/OP8Wx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OP8Wx.png" alt="enter image description here" /></a></p>
  <p>I basically used this dataset <a href="https://www.kaggle.com/kyanyoga/sample-sales-data" rel="nofollow noreferrer">https://www.kaggle.com/kyanyoga/sample-sales-data</a> and loaded it into a postgressql database.</p>
  <pre><code>-- 1. Create temp table to house temporary results
  DROP TABLE IF EXISTS product_quantity;
  CREATE TEMP TABLE product_quantity
   (product_line varchar, this_month_quantity integer, last_month_quantity integer)
  
   --2. Quantity ordered for each Product line for current month is inserted into temporary table.
  INSERT INTO product_quantity (product_line, this_month_quantity, last_month_quantity)
  SELECT &quot;productline&quot;, SUM(&quot;quantityordered&quot;), 0
  FROM test_schema.sales_data_sample
  where &quot;month_id&quot; = 3 and &quot;year_id&quot; = 2003
  GROUP BY &quot;productline&quot;;
  
  --3. Quantity ordered for each Product line for last month is inserted into temporary table.
  INSERT INTO product_quantity (product_line, this_month_quantity, last_month_quantity)
  SELECT &quot;productline&quot;, 0, SUM(&quot;quantityordered&quot;)
  FROM test_schema.sales_data_sample
  where &quot;month_id&quot; = 2 and &quot;year_id&quot; = 2003
  GROUP BY &quot;productline&quot;;
  
  --4. Retrieve required results.
  select
      &quot;product_line&quot;,
      sum(&quot;this_month_quantity&quot;) as &quot;this_month_quantity&quot;,
      sum(&quot;last_month_quantity&quot;) as &quot;last_month_quantity&quot;
  FROM product_quantity
  group by &quot;product_line&quot;
  
  </code></pre>