how do you write multiple sql queries in powerpivot

jersey

New Member
Joined
Mar 9, 2012
Messages
28
Hi,
Is it possible to paste 2 queries in powerpivot?
The first query creates a temp and the 2nd query bring in some additional columns.

Thanks,
Cindy
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
You could always just put that in a SPROC/VIEW in sql, That is probably the "more correct" thing to do. That said, I suspect it would work just fine -- power pivot does let you write queries when importing data. Did you try it?
 
Upvote 0
I don't know about additional columns, but I know that T-SQL allows unions. (I think that's what PowerPivot runs on, in any case I mean the SQL that's used in PP)

For example, this code would get you a sum of all activity for 2011 and older, followed by the detail for 2012 and newer:

Code:
SELECT  GLSummary.Company_Key
  ,GLSummary.GLAccount_Key
  ,SUM(GLSummary.Debit) AS Debit
  ,GLSummary.Project_Key
  ,SUM(GLSummary.Credit) AS Credit
,Max(FinancialPeriod.FinancialPeriod) AS FinancialPeriod
 ,Max(FinancialPeriod.FinancialPeriod_Key) AS FinancialPeriod_Key
FROM
  FinancialPeriod
  INNER JOIN GLSummary
    ON FinancialPeriod.FinancialPeriod_Key = GLSummary.FinancialPeriod_Key
WHERE
(FinancialPeriod.FinancialPeriod)<='12/31/2011'
GROUP BY
  GLSummary.Company_Key
  ,GLSummary.GLAccount_Key
  ,GLSummary.Project_Key


UNION


SELECT
  GLSummary.Company_Key
  ,GLSummary.GLAccount_Key
  ,SUM(GLSummary.Debit) AS Debit
  ,GLSummary.Project_Key
  ,SUM(GLSummary.Credit) AS Credit
,(FinancialPeriod.FinancialPeriod) AS FinancialPeriod
 ,(FinancialPeriod.FinancialPeriod_Key) AS FinancialPeriod_Key
FROM
  FinancialPeriod
  INNER JOIN GLSummary
    ON FinancialPeriod.FinancialPeriod_Key = GLSummary.FinancialPeriod_Key
WHERE
(FinancialPeriod.FinancialPeriod)>='1/1/2012'
GROUP BY
  GLSummary.Company_Key
  ,GLSummary.GLAccount_Key
  ,GLSummary.Project_Key
,FinancialPeriod.FinancialPeriod
,FinancialPeriod.FinancialPeriod_Key
 
Upvote 0

Forum statistics

Threads
1,223,993
Messages
6,175,845
Members
452,675
Latest member
duongtruc1610

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top