OBIEE: Cannot Do Subtraction between Two Columns

I would like to see the difference of a customer's spending in the current Vs. previous period. So each row contains the data of one customer. And my first field (column A) lists out the customer's spending in the current period and second field (column B) for the previous period. I tried to calculate the difference in my third field (column C).
However, since some of the cells in column A are "null", the respective cells in column C were also shown as "null".
I tried converting column A's null cells into 0 using ifnull. But the respective cells in column C still cannot do the subtraction.
Please help! Thanks in advance.

Can you try this instead of ifnull and see how it works
case when col is null or col='' then 0 else col end
If helps mark

Similar Messages

  • How to get the difference between two columns in a column group

    Hi All,
    My first time here and really new to programming. I would like to get the difference between 2 columns that are inside 
    a column group.
    Here is my sample table below: The Column Group is PeriodNumber and can only choose 2. like 1 and 2.. I would like to have a third row which will simply calculate the difference between the amounts in PeriodNumber 1 and 2.
                                PeriodNumber          
    Account                    1                            2     
    1) Cash                10,000                15,000
    2) Receivables      12,000                11,500
    3) Equipment          5,000                  5,500
    Total Assets          27,000                32,000

    Hi yabgestopa,
    From your description, you want to get the difference between two columns in a column group. After testing it in my environment, we can use custom code to achieve your requirement. For more details, you can refer to the following steps:
    Copy the custom code below and paste it to your report. (Right-click report>Report Properties>Code)
    Dim Shared Num1 As Integer
    Dim shared Num2 As Integer
    Public Function GetAmount(Amount as Integer, Type as String)
    If Type = "1" Then
    Num1=Amount
    Else
    Num2=Amount
    End If
    Return Amount
    End Function
    Public Function GetDif()
    Return Num1-Num2
    End function
    Right-click the second column to insert a third column with Outside Group-Right.
    Then use the expressions below in the matrix.
    =Code.GetAmount(Fields!Amount.Value,Fields!PeriodNumber.Value)
    =code.GetAmount(Sum(Fields!Amount.Value),Fields!PeriodNumber.Value)
    =Code.GetDif()
    The report looks like below.
    If you have any questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Find the difference between two columns in an ssrs matrix ? MSCRM

    Hi All,
    I am working in reporting part of our project (On-line MSCRM 2013) & in reporting services.
    I am trying to create report using fetch xml based. Below is the snap what we required the result.
    Kindly help me, how to get the difference in both column. (Its a matrix table where year is grouped).
    We need difference between both year Like (Plan Revenue of 2013 & Plan Revenue of 2014 difference in Plan Revenue Diff section) and same for Actual
    Revenue.
    https://social.microsoft.com/Forums/en-US/054d5ca4-0d38-4dc6-84a8-88866cc228fe/find-the-difference-between-two-columns-in-an-ssrs-matrix-mscrm?forum=crmdevelopment
    Thanks,
    Mohammad Sharique

    Hi Bro,
    I used parametrized option for year and done the report,Currently we are getting values in Difference column now i want to show
    that value in percentage. How can we show the percentage based on that value. Means i want to show the Difference in Percentage. 
    Kindly help me i tried but getting some issue. Below i am mentioning the code and snap with result.
    Below expression using to showing Plan Revenue in Percentage for year.
    =
    Sum(IIF(Fields!new_year.Value =Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    - Sum(IIF(Fields!new_year.Value =Parameters!EndYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))
    /IIF(Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0)))>0,
    (Sum(IIF(Fields!new_year.Value = Parameters!StartYear.Value,cdec(Fields!new_planrevenueValue.Value/1000), cdec(0))))
    ,1)
    )*100))
    Result issue is as below in snap with highlighted in red colour.
    Kindly help me on this issue also :)

  • How to find differences between two columns

    Hello I need the formula to spot differences between two columns and to write on a third one if the same name appear on the two columns.
    For example:
    rome berlin true
    berlin moscow false
    chicago toronto true
    toronto chicago true
    florence
    Thanks
    Lorenzo

    You should be able to use COUNTIF where the range is th first column and the condition is the word in the second column. If the result is greater than zero then the word is in both columns.

  • Results row calculation between two column result  in BEx Report.

    I want to use weighted average method between two keyfigure.
    for example consider the following secnario.
    CH        Kf1       Kf2
    A         10        5
    B          6        4
    C          3        2
    Result     19     b]4.21</b>
    how 4.21 is ((105)+(64)+(3*2))/total of Kf1(ie 19)
    ( A value(Kf1Kf2)+ B value (Kf1Kf2) + C Value (Kf1*Kf2))/total value (Kf1) = 4.21
    is it possible to achieve the above result for Kf2.
    With regards,
    Hari

    Hello,
    I cannot able to use Excel Macro functionality since it is a drill down report and report cells varies based upon the selection parameter.
    and also i can't  able to use Calculation, since this report contains lot of columns and if i use  the formula, one more result column i have to include in all key figures and also business users not able to understand the report....
    Is it possible to create a variable structure, for example user is executing for 10 days , the structure should display for only 10 days ans also i create structure for 31 days (ie one month)..
    With regards,
    Hari

  • Webi Report Data compare between two columns

    There is two different queries in Webi Report BI 4.1
    Query 1 - Name_1 == 100 records
    Query 2 - Name_2 == 75 records
    On the report need to compare the data between Name_1 and Name_2.
    Need report level flag as a second column
    name_1 = name_2 = Y
    name_1 <> name_2 = N
    One the report there is only two columns Name_1 Flag(Y/N)
    1. If statement is not working at all in this scenario
    2. Merge dimension is not useful since I need to treat these columns separately on the report.

    Hi Suri,
    As the objects belong to two different queries, the comparison might not work as they are not merged and incompatible.
    You can try creating a seperate query and can use subquery in it.
    For example:
    SELECT NAME_1 FROM QUERY_1
    WHERE
    NAME_1 NOT IN (SELECT NAME_1 FROM QUERY_2)
    This will display the names which are not common.
    Hope it will help.
    Regards,
    Yuvraj

  • Division between two columns in pivot table in Answers

    Hi all
    In answers
    if I have two columns in my pivot table say column A and Column B, how can I use a division of Column B by Column A to derive Column C. I am unable to do that using the "New Calculated column feature" or in the criteria section. I keep getting either 0 or 1. I even tried changing the format to show two decimal places and am still unable to get the result.
    Thanks
    B

    Thanks,
    our issue is that we want to do our calculations at the summary level (region level of the company) and not at the detail level. However we cannot do this at the aggregate level because this is a moving total for the last 7 days worth of data.
    Also, Answers (even in Criteria) does not seem to be doing division properly. We are just not getting the results when we do col A/ Col C. We are in 10.1.3.4 on windows xp against SQL Server
    Any ideas?
    Edited by: Mid Atlantic on Jul 22, 2011 5:33 AM

  • Foreign Key join between two columns in a dimension to one column in Fact

    Hi,
    I have a requirement to join two columns in a Dimension to the same column in the fact.
    My reports contains columns from this dimension and will need to use both the joins to get the correct values. So I am not sure if I create an alias to join the second column, if that will be output incorrect values.
    How can we achieve this so that I can still use columns from the dimension and still run both the joins in my SQL eventually.
    Dimension
    Column 1
    Column2
    Fact
    Column 3
    Need to map Column1--->Column 3 and Column2 -----> Column 3
    Thanks

    I put it in Dimension and dimension extension scenario with a fact
    The possible scenarios are:
    1) Column1--->Column 3 and Column2 -----> Column 3
    Both Column1 and Column2 have their own logical tables in BMM
    2)
    Column1--->Column 3
    Column1--->Column2
    In this case You have Logical table with 2 different sources Column1 and Column2 using column mapping.
    you can go for multiple logical sources in this case, based on column selection tables in the join condition

  • Running total and calc between two column (subtraction)

    Hi Experts!,
    I have a simple requirement but getting me frustrated :( I need to calculate stock on a series of transaction
    this is my order table:
    OrderNo | Item | Delivery | OrderQty
    A-101 | G001 | 20110721 | 200
    A-104 | G001 | 20110722 | 300
    A-102 | GA02 | 20110721 | 210
    and my stock table :
    Item | stockQty
    G001 | 300
    GA02 | 0
    What i want to accomplish is something like this:
    OrderNo | Item | Delivery | OrderQty | StockOut
    A-101 | G001 |20110721 | 200 | 200
    A-104 | G001 |20110722 | 300 | 100
    A-102 | GA02 |20110721 | 210 | 0
    i believe there is must be a way to accomplish this, without using to create extra dummy table to store
    qty of Stock out (stock-orderqty),
    waiting for respons,
    Thanks!

    Try this
    with order1
    as
    select 'A-101' orderno, 'G001' item, 20110721 delivery, 200 orderqty from dual union all
    select 'A-104', 'G001', 20110722, 300 from dual union all
    select 'A-105', 'G001', 20110723, 250 from dual union all
    select 'A-102', 'GA02', 20110721, 210 from dual union all
    select 'A-103', 'GA02', 20110721, 300 from dual
    ), stock
    as
    select 'G001' item, 600 stockqty from dual union all
    select 'GA02', 500 from dual
    select orderno, item, delivery, orderqty, case when qty <= stockqty then orderqty else stockqty - qty1 end stockout
      from (
             select orderno, item, delivery, orderqty, qty, nvl(lag(qty) over(partition by item order by orderno), 0) qty1, stockqty
               from (
                      select orderno, o.item, delivery, orderqty, sum(orderqty) over(partition by o.item order by orderno) qty, stockqty
                        from order1 o
                        join stock s
                          on o.item = s.item
           )Note: Tables defined in the WITH caluse are sample table to show you how the SQL works. You can just use the SELECT statement with your original table.

  • Subtraction of two columns

    Hi,
    I have two fields cheque date and posting date in the ROW SECTION of my BEx query.
    I want to display the subtraction of these two dates in COLUMN SECTION of the query.
    Can anybody tell me how to do that.
    Thanks and Regards,
    Vikrant

    Hi,
    I think you need to calculate no. of days.
    You need to create 2 Formula variables with Replacement path (selecting appropriate Characteristics i.e. dates in your case) and in the Currency/Unit tab, select Date (default will be Number).
    Then in the Detail view of the main Formula, perform subtraction as required. You can also apply conditions viz. IF posting_date <> 0, THEN perform subtraction, etc.
    Hope it helps!
    Regards,
    Dhaval

  • Calculating a difference between two columns in a crosstab report

    I have a crosstab report showing # of sales by salesperson in each of 2 years and within each of 2 categories of salesperson (old vs new). I want to create a column showing the difference between sales in 2009 and 2010 within new salespersons  and then a column showing the difference between 2009 and 2010 within old salespersons. I can't figure out how to pinpoint in the variable editor the column containing 2009 sales by new agents. Any advice?

    You can hard-code the formulas like this:
    =Sum([Sales]) Where ([Year] = 2009)
    =Sum([Sales]) Where ([Year] = 2010)
    Then the variance becomes:
    =Sum([Sales]) Where ([Year] = 2010) - Sum([Sales]) Where ([Year] = 2009)
    The challenge with this is the years are not dynamic, but I figure I will throw this out first and see if it gets you what you want to start with.

  • How to get time in hours minutes and seconds subtract between two varchar t

    Hi all,
    I have two varchar variable which has value like this
    v_outpunch1:='17:50:00'
    and v_Shifttime:='18:00:00'
    this both time i am subtracting here and storing in another varchar variable
    which is like this.
    v_EarlyLeaverstimeformat := LPAD((extract(hour from TO_TIMESTAMP (v_ShiftTime,'HH24:mi:ss')) - extract(hour from TO_TIMESTAMP (v_OutPunch1,'HH24:mi:ss'))), 2, '0')||':'|| LPAD((extract(minute from TO_TIMESTAMP (v_ShiftTime,'HH24:mi:ss')) - extract(minute from TO_TIMESTAMP (v_OutPunch1,'HH24:mi:ss'))), 2, '0')||':'|| LPAD((extract(second from TO_TIMESTAMP (v_ShiftTime,'HH24:mi:ss')) - extract(second from TO_TIMESTAMP (v_OutPunch1,'HH24:mi:ss'))), 2, '0');
    it's not subtracting value correctly.
    thanks

    You shouldn't store time information in a varchar2, but if you do
    declare
      v_outpunch1 varchar2(100);
      v_Shifttime varchar2(100);
      v_EarlyLeaverstimeformat varchar2(100);
    begin
      v_outpunch1:='17:50:23';
      v_Shifttime:='18:00:00';
      v_EarlyLeaverstimeformat := numtodsinterval( to_date( v_Shifttime, 'hh24:mi:ss' ) - to_date( v_outpunch1, 'hh24:mi:ss' ), 'day' );
      dbms_output.put_line( v_EarlyLeaverstimeformat );
      v_EarlyLeaverstimeformat := to_char( trunc( sysdate ) + ( to_date( v_Shifttime, 'hh24:mi:ss' ) - to_date( v_outpunch1, 'hh24:mi:ss' ) ), 'hh24:mi:ss' );
      dbms_output.put_line( v_EarlyLeaverstimeformat );
    end;

  • Find many-to-many relationship between two columns in one query

    Hi All,
    How can I run one query to determine if Column1 and Column2 in the following table have a many-to-many relationship?
    Column1
    Column2
    Column3
    b
    x
    s
    b
    x
    t
    c
    x
    s
    c
    y
    s
    c
    y
    t
    Just by eyeballing it, we know there is, but in a real life situation, you cannot eyeball millions of records to make that decision.
    I am using Access 2007.  (SQL script that works with Access 2007 will be great, but script for SQL Server will be fine too.)
    BI Analyst

    Hi BI Analyst,
    Take a look at this code:
    IF OBJECT_ID('tempdb..#experiment') IS NOT NULL DROP TABLE #experiment;
    CREATE TABLE #experiment (c1 CHAR(1), c2 CHAR(1), c3 CHAR(1))
    INSERT INTO #experiment (c1,c2,c3) VALUES ('b','x','s'),('b','x','t'),('c','x','s'),('c','y','s'),('c','y','t')
    SELECT c1, c2, c1+c2 AS bind,
    COUNT(c1) OVER (PARTITION BY c1+c2) c1perbind,
    COUNT(c2) OVER (PARTITION BY c1+c2) c2perbind,
    COUNT(c1+c2) OVER (PARTITION BY c1) bindsperc1,
    COUNT(c1+c2) OVER (PARTITION BY c2) bindsperc2
    FROM #experiment
    What your question asks is if there can be determined a many-to-many relationship. A many-to-many relationship is logical relation comprised of a pair of one-to-many relationships. The code above shows you which relational pairing occur in these one-to many
    relationships. c1perbind (or c2) >1 indicates a one to many relation from that relational pairing, whereas the bindsperc1 indicates how many relations the individual c1 belongs to.
    Now look at this code:
    SELECT c1, c2, bind,
    COUNT(c1) OVER (PARTITION BY c1+c2) c1perbind,
    COUNT(c2) OVER (PARTITION BY c1+c2) c2perbind,
    COUNT(bind) OVER (PARTITION BY c1) bindsperc1,
    COUNT(bind) OVER (PARTITION BY c2) bindsperc2
    FROM (SELECT DISTINCT c1, c2, c1+c2 AS bind FROM #experiment ) Q1
    With the subquery reducing the set for the windows to operate on to distinct pairs the bindsperC1 and bindsperC2 will show count greater than one if they belong to a one-to-many relationship. When both are greater than 1 those rows are proof that the relationship
    between C1 and C2 is a many-to-many.
    If you're happy and you know it vote and mark.

  • Query help needed in finding max value between two columns

    I have a table as follows:
    -- INSERTING into TESTTABLE
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('A','4.5','AA',0.3,'AB',5.5);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('B','1','BB',2.5,'BC',6.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('C','2.6','CC',3.3,'CD',1.4);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('D','1.8','DD',2.9,'DE',1.2);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('E','6.8','EE',4.8,'EF',9.6);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('F','2.0','FF',6.34,'FG',3.9);
    Insert into TESTTABLE (COLA,COL2,COLC,COLD,COLE,COLF) values ('G','1.7','GG',3.6,'GH',5.8);
    I want to get results as follows:
    COLA COL2 MaxCol MaxColVal
    A 4.5 AB 5.5
    B 1 BC 6.9
    C 2.6 CC 3.3
    D 1.8 DD 2.9
    E 6.8 EF 9.6
    F 2.0 FF 6.34
    G 1.7 GH  5.8I want to get the max value of either of the columns COLD or COLF.. Whichever column has got max value, then the corresponding value of COLC and COLE should be returned..
    For eg., in first row, COLF has higher value than COLD.. ie., COLF = 5.5 > COLD = 0.3, so for row1, i want the result as MaxCol is AB and MaxColvalue is 5.5..
    Similarly for third row, COLD =3.3 > COLF=1.4, so for 3rd row, i want the result as MaxCol is CC and MaxColvalue is 3.3
    How is it possible to do this in a qery? Any help.. please..

    SQL> select cola
      2       , col2
      3       , case greatest(cold,colf)
      4         when cold then colc
      5         else cole
      6         end maxcol
      7       , greatest(cold,colf) maxcolval
      8    from testtable
      9  /
    C COL MA  MAXCOLVAL
    A 4.5 AB        5,5
    B 1   BC        6,9
    C 2.6 CC        3,3
    D 1.8 DD        2,9
    E 6.8 EF        9,6
    F 2.0 FF       6,34
    G 1.7 GH        5,8
    7 rijen zijn geselecteerd.Regards,
    Rob.

  • Width between two columns.

    hello every one,i have a table which hve column of varchar2(100),number and so on.
    when i describe the table the data type are display much away from column name.
    i scroll then see its data type ,there is any way i can see close them.thanxxx

    SET PAGESIZE 200;
    SET LINESIZE 125;
    You can set it as per your requirement.

Maybe you are looking for