Search code examples
sqlcrystal-reportssapb1crystal-reports-8.5

Actual vs Budget variance Crystal Reports repeating columns


I am new to Crystal reporting. I am trying to join multiple tables I have properly working queries but when I try to add them in SAP CR editor. One of the column shows up fine but others start repeating values.

I am using the following tables:

  • Budget A/C Code --OACT, AccName -- Budget Relevant A/C Name
  • Current Month Actual -- OJDT join JDT1 -- Pick From JE
  • Current Month Budget -- OBGT Join BGT1-- Pick From Budget
  • Current Month Variance -- JDT1 - BGT1 -- Difference b/w Current Month Actual and Current Month Budget
  • Year To Date Actual -- Sum of JDT1 -- Total PnL Balance for the current fiscal year
  • Year To Date Budget -- Sum of BGT1 -- Total Budget Balance for the current fiscal year
  • Year to Date Variance --Actual - Budget --Difference b/w Year to Date Actual and Year to Date Budget

Report format list of columns I want to display:

  • Account Names
  • Current Month Actual
  • Current Month Budget
  • Current Month Variance
  • Year to Date Actual
  • Year to Date Budget
  • Year to Date Variance

What I have done:

    SELECT
    sum (T1.DebLTotal) actual,
    SUM(T3.Debit) budget,
    **OACT.AcctName ?**

    from
    OBGT T0  INNER JOIN BGT1 T1 ON T0.[AbsId] = T1.[BudgId], 
    OJDT T2 INNER JOIN JDT1 T3 ON T2.[TransId] = T3.[TransId]

    group by T3.Account  -- Some how i want to join OACT to get account names from AcctName 
                         -- field of budget relevant accounts Join on acctcode field

Solution

  • Finally i have completes a portion

    select
    
      T3.[AcctCode],sum(T1.[Debit]) as Actual, sum(T5.[DebLTotal]) as Budget
      into #abc
      from 
    
      [dbo].[JDT1]  T1 INNER JOIN [dbo].[OJDT]  
      T2 ON T1.[TransId] = T2.[TransId] INNER JOIN 
      OACT T3 ON T1.[Account] = T3.[AcctCode], OBGT T4 
      INNER JOIN BGT1 T5 ON T4.[AbsId] = T5.[BudgId]
    
      group by T3.AcctCode
    
      select OACT.AcctName, #abc.Actual, #abc.Budget 
     from OACT ,#abc where #abc.AcctCode=OACT.AcctCode 
    
      Drop table #abc