我在SQL Server中的存储过程中有以下SQL代码,它将数据提供给报表。现在我们正在实现SSAS多维数据集来处理数据。我有一个事实表,其中包含所有度量和退化维度。我们在将低于计算转换为MDX时遇到问题。此计算完全取决于“开始日期”和“结束日期”参数,因此无法在ETL时间完成。当客户在报告上选择开始日期和结束日期时,必须执行此操作。
任何人都可以帮助/指导我如何将下面的代码转换为MDX吗?作为MDX世界的新手,我面临以下问题
一个。缺少像结构这样的临时表,有助于在处理过程中存储临时数据。
湾CLR或COM对象支持存储过程。为什么缺少SQL / MDX过程?
是否可以从多维数据集数据执行以下计算?
Select
rundate ,Entity ,MasterEntity ,TransactionDate ,BuyOrSell ,Quantity2 ,Quantity1 ,Quantity3 ,Quantity4 ,Profit1
,Profit2 ,Profit3 ,transactionId ,closingtransactionId
into #TempData from [Fact_Test]
Where datediff(d,@StartDate,rundate)>=0 and datediff(d,rundate,@EndDate )>=0 order by rundate
Select Rundate,TransactionDate,BuyOrSell,Quantity2,transactionId,closingtransactionId
into #ClosedTransactions from #TempData Where BuyOrSell = 'C'
Select
affected.Rundate AS 'OpenTransactionDate', affected.BuyOrSell as 'OpenTransaction_BuyOrSell',
affected.Quantity3 as 'OpenTransaction_Quantity1' , affected.Quantity1 as 'OpenTransaction_Quantity2',
affected.Profit2 as 'OpenTransaction_Profit2', affected.transactionId as 'OpenTransaction_transactionId',
affected.closingtransactionId as 'ClosedTaxlot_ClosedingtransactionId'
into #AffectedOpenTransaction from #TempData affected
where affected.transactionId in (select distinct transactionId from #ClosedTransactions)
and affected.rundate between @StartDate and @PreviousDateFromEndDate and affected.BuyOrSell = 'O'
select
CLOSED.Rundate as 'ClosingDate', CLOSED.Quantity2 as 'ClosedQuantity',
CLOSED.transactionId as 'closingtransactionId', AFFECTED.OpenTransaction_transactionId as 'OpeningtransactionId',
AFFECTED.OpenTransaction_Quantity2 as 'AffectedQuantity', AFFECTED.OpenTransaction_Profit2 as 'Affected_Profit2',
AFFECTED.OpenTransactionDate as 'AffectedTransactionDate',Convert(float,0) as 'Profit2_Adjusted'
into #TempProfit2
from #ClosedTransactions CLOSED
inner join #AffectedOpenTransaction AFFECTED
on ( CLOSED.transactionId = AFFECTED.OpenTaxlot_transactionId and datediff(d,AFFECTED.OpenTransactionDate,CLOSED.Rundate)>0 )
update #TempProfit2
set Profit2_Adjusted = case when AffectedQuantity <>0 then(ClosedQuantity * 1.0/(AffectedQuantity*1.0)) * Affected_Profit2 else 0.0 end
select
closingtransactionId, ClosingDate,
Sum( Case When datediff(d,AffectedTransactionDate,ClosingDate)> 0 Then Convert(float,Profit2_Adjusted) else 0.0 End ) as UnrealizedPNL_Adjusted
into #Profit2_Adjusted
from
#TempProfit2
group by closingtransactionId,ClosingDate
select
MasterEntity,Entity, sum(Profit1 + isnull(Profit2_Adjusted,0)) as FinalProfit1,
sum(Profit2 - isnull(Profit2_Adjusted,0)) as FinalProfit12,sum(Profit3) as Profit3,
sum(Profit1 + isnull(Profit2_Adjusted,0)) + sum(Profit2 - isnull(Profit2_Adjusted,0)) + sum(Profit3) as TotalMTMPNL
from #TempData
left outer join #Profit2_Adjusted
on (#TempData.transactionId = #Profit2_Adjusted.closingtransactionId
and datediff(d, #Profit2_Adjusted.ClosingDate, #TempData.Rundate) = 0 and #TempData.BuyOrSell = 'C' )
group by MasterEntity,Entity
order by MasterEntity,Entity