Oracle Analytics Cloud and Server

Welcome to the Oracle Analytics Community: Please complete your User Profile and upload your Profile Picture

How to add a variance into a pivot table

Received Response
290
Views
12
Comments
Rank 6 - Analytics Lead

Hi all,

I've seen the "variance in a pivot" question asked around here a fair bit and and happy that this is fairly easy using a calculated item.
My issue seems a little more complex though.

Basically, i'm trying to create the following in a pivot. 

Debit/CreditDebitDebitDebitCreditCreditCreditVariance
ProductP1P2P3P1P2P3Variance
BranchRegionNameAmountAmountAmountAmountAmountAmountAmount
11111TestBranch30555032033
22222TestBranch21020301510-34

I can't seem to work out how to get the variance column to be the total debits subtract the total credits but only have the single column at the end.
I've tried adding a union with a "variance" value in the debit/credit and product columns but it seems to act strangely.
I was hoping there would be an easier way that I wasn't aware of.


Thanks in advance,
Adam

Welcome!

It looks like you're new here. Sign in or register to get started.
«1

Answers

  • Rank 6 - Analytics Lead

    You can create a new column in criteria like below.

    SUM(case when ColumnDebit/Credit ='Debit' then Amount) - SUM(case when ColumnDebit/Credit ='Credit' then amount)

    and place it in the Rows Area of Pivot. the only thing is variance will come first.

  • Rank 8 - Analytics Strategist

    Whenever there is a combination of case and summation logic my best recommendation is to put it in a physical calculation in the subject area in the rpd.

    If this is not an option then sum(case... etc as recommended by @Asim should work, but you may also need to set the properties on that column to server complex aggregate or you may find strange results as you have been seeing, the strange results are because OBIEE to optimise speed as a bias towards logical calculations, and in the case (no pun intended) of your sum (case logic...etc logic it cannot aggregate first and get the correct result.

  • Rank 6 - Analytics Lead

    When it is placed in Rows area how aggregation matters ?

  • Rank 6 - Analytics Lead

    I have already tried your suggestion above but for some reason instead of subtracting one from the other, it adds them together.
    I have also tried multiplying one by -1 so that when it adds together, it effectively does the subtraction but it still adds the figures together but results in a negative of the value instead of a positive.
    I will try and server complex aggregate suggestion first and if that doesn't work, i'll the value to the physical database.

    Thanks for your suggestions guys. WIll update when I know.

    PS I should have mentioned that the order of the columns is very important as the data is being consumed by a downstream process that cannot be changed easily.

  • Rank 6 - Analytics Lead

    Ok so it seems that i'm still missing something.

    I've simplified it down to one branch to see if I can see what is happening.

    I start off with this (Note: I have multiplied the Debits by -1 so that they're shown as negatives instead of positives):

    Branch
    Product
    Debit/Credit
    Amount
    1P1Debit-13,142
    1P1Credit49,331
    1P2Debit-164
    1P2Credit292
    1P3Debit-5,615
    1P3Credit34,450

    Now, the next step is to change the product field to the word 'Variance', which effectively changes the group by.

    Branch
    Product
    Debit/Credit
    Amount
    1VarianceDebit-18,921
    1VarianceCredit84,073

    So far, so good.... Now we want to change the debit/credit to the word 'Variance' as well so we are left with only one row.
    My expectation is that it will add the two numbers above together and we will be left with 65,152.

    The result is:

    Branch
    Product
    Debit/Credit
    Amount
    1VarianceVariance102,993

    I have tried using server complex aggregate, server determined and sum as the default aggregation on the field.
    All give the same result.

    Any ideas? It seems to work as expected until I remove the debit/credit field.


    Thanks,
    Adam

  • Rank 8 - Analytics Strategist

    cf my previous comment that you would be better doing this in the rpd.

    But, if it must be answers, have you tried using the filter functionality in function editor to create the figures, you can nest filters to achieve your ends.

    Or, what happens if you keep the DR / CR field but use display:none to suppress it, then pivot?

  • Rank 6 - Analytics Lead

    I dont think it will add to the results .. I will show you an example.

    Here i kept debit - credit

    In OBIEE Pivot as far as i know we cannot add a column after the pivoted columns.

    pastedImage_0.png

  • Rank 6 - Analytics Lead

    Hi Asim,

    This is fine but as mentioned, I need the Variance field to remain the last column in the pivot.


    Robert,

    Could you please advise how you would do this in the RPD?

  • Rank 6 - Analytics Lead

    Worked it out guys... For those with a similar issue, you can use the Filter function instead of the Case function and for some weird reason, it works as intended.
    The formula I used for my amount measure is as follows:

    FILTER("Transactions"."Tran Amount - Including Reversals" USING ("Transactions"."Debit Credit" = 'Debit')) - FILTER("Transactions"."Tran Amount - Including Reversals" USING ("Transactions"."Debit Credit" = 'Credit'))

    I hope that helps somebody out in the future.

  • Rank 6 - Analytics Lead

    So How did you add it as the last column in pivot?

    Also Filter function is better than wierd case, But unfortunately Oracle BI will convert the filter function to case statement when executing in DB as database doesnt know what is filter function

Welcome!

It looks like you're new here. Sign in or register to get started.