Query Assistance - Calculating percentage

Greetings,
I may just be looking at this for way to long and not seeing the proper coding/syntax
required to accomplish what it is I am trying.
I have one query to figure out an overall count for each organization in a database. I
then have a second query to figure out the success rate count to compare to the
overall count per organization. I am running the second query inside the <cfoutput>
of the first query to achieve the desired count/display intended.
The overall and the success counts are displaying as I intend them to. However, I
am unable to get the percentage part to work. Perhaps someone can look at my
code and layout to see where it is I am failing. I have provided the desired look and
my code below for review.
I am certainly open to suggestions on how to do it differently / better, should someone
have an insight on how to accomplish my desired outcome.
CF = CF8
DB = MySQL
Thanks in advance
Leonard B
===== Desired Look =====
Total Attempts
First Attempts
Percent
Organization Name
20
18
Org. Name
40
33
Org. Name
51
44
Org. Name
===== Code Below =====
<cfquery name="rs_attempts" datasource="DSN">
SELECT
Count(airway_management.agency_cert_number) AS agency_count,
airway_management.agency_cert_number,
airway_management.year_of_call,
airway_management.et_attempts,
airway_management.et_attempts_successful,
airway_management.dept_org
FROM
airway_management
WHERE
airway_management.year_of_call = <cfqueryparam cfsqltype="cf_sql_integer" value="2009">
GROUP BY
airway_management.dept_org
</cfquery>
<table width="0" border="1" cellpadding="0" cellspacing="0">
<tbody>
<tr>
    <td><div style="font-family: Arial; font-size: 13px">Total Attempts</div></td>
    <td><div style="font-family: Arial; font-size: 13px">First Attempts</div></td>
    <td><div style="font-family: Arial; font-size: 13px">Percent</div></td>
    <td><div style="font-family: Arial; font-size: 13px">Organization Name</div></td>
</tr>
<cfoutput query="rs_attempts">
<tr>
    <td><div style="font-family: Arial; font-size: 13px">#agency_count#</div></td>
        <cfquery name="rs_1_attempts" datasource="DSN">
        SELECT
        agency_cert_number,
        dept_org,
        year_of_call,
        et_attempts,
        et_attempts_successful
        FROM
        airway_management
        WHERE
        year_of_call = <cfqueryparam cfsqltype="cf_sql_integer" value="2009"> AND
        agency_cert_number = <cfqueryparam cfsqltype="cf_sql_varchar" value="#rs_attempts.agency_cert_number#"> AND
        et_attempts = <cfqueryparam cfsqltype="cf_sql_integer" value="1"> AND
        et_attempts_successful = <cfqueryparam cfsqltype="cf_sql_varchar" value="Yes">
        </cfquery>   
        <cfset percent = ((#rs_attempts.recordcount# - #rs_1_attempts.recordcount#)*100)>
    <td><div style="font-family: Arial; font-size: 13px">#rs_1_attempts.recordcount#</div></td>
    <td><div style="font-family: Arial; font-size: 13px">#NumberFormat(percent,999.00)#</div></td>
    <td><div style="font-family: Arial; font-size: 13px">#dept_org#</div></td>
</tr>
</cfoutput>
</tbody>
</table>

Try replacing this line
<cfset percent = ((#rs_attempts.recordcount# - #rs_1_attempts.recordcount#)*100)>
with
<cfset percent = #(rs_attempts.recordcount - rs_1_attempts.recordcount)*100#>
Not sure on the brackets though - if not try
<cfset percentWorking= #rs_attempts.recordcount - rs_1_attempts.recordcount#>
<cfset percent = #working * 100#>
Mi-ul

Similar Messages

  • SQL query not calculating

    SQL query not calculating
    gross_amount is giving the value of extended_amount and the gross_price_rc is giving the value of unit_selling_price
    select customer_trx_line_id,
    ( extended_amount / 1- (decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) GROSS_AMOUNT,
    ( unit_selling_price /1-(decode(decode(attribute6,null,0)+decode(attribute7,null,0)+decode(attribute8,null,0)+decode(attribute9,null,0)/100,null,0,1,0))) gross_price_rc
    from ra_customer_trx_lines_all
    where attribute6 is not null or attribute7 is not null or attribute8 is not null or attribute9 is not null
    whats the isuue here??
    Thanks

    decode(attribute7,null,0)Looking at it again, this always returns 0 or NULL, so it not really surprising
    DECODE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions040.htm#i1017437
    CASE
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/expressions004.htm#i1033392

  • Query result in percentage

    Hello, I am lookg for the answer for the query result in percentage by doing a select statement.
    Thanks.
    The following works fine ....
    SELECT
    Territory, Sum(SalesDollars)
    FROM
    SALES
    GROUP BY
    Territory
    result:
    Ohio: $4000
    New York: $2000
    Now I need the result to return a percentage ...
    Ohio: 66.6%
    New York: 33.3%

    Hi,
    with Sales as(
      SELECT 'Ohio' AS Territory, 2000 as SalesDollars from dual
      UNION ALL
      SELECT 'Ohio', 2000 from dual
      UNION ALL
      SELECT 'New York', 1000 from dual
      UNION ALL
      SELECT 'New York', 1000 from dual
    SELECT Territory, Sum(SalesDollars),
      TO_CHAR(ratio_to_report(Sum(SalesDollars)) over (partition by 1) * 100, '99.9') || '%'
    FROM SALES
    GROUP BY Territory;Best regards,
    Dima

  • Calculated Percentage Columns in Pivot Table loose formating in Excel

    I have a simple report built using pivot table ( OBIEE 11.1.1.5.0)
    1 Metric and 1 dimension using pivot table. and I duplicated the metric column and change it to % column.(Show data as % of column). SO far so good. Below is the snapshot
    http://tinypic.com/r/2s14xa9/7
    Now i download the report in excel and all the % values are messed up . Below is how it looks
    http://tinypic.com/r/bede90/7
    I tried messing with data formats etc..nothing works.. I cannot add a custom column format to the metric column since it will impact the derived % column.
    Is this a bug ?Any pointers ..
    Thanks

    Hi,
    Follow up this SR:
    SR 3-5060435331: Calculated Percentage Columns in Pivot Table loose formating in Excel
    Workaround: (not sure may be give a try)
    also give a try like below one then try to download it may work.
    In that % column -->add the below statement in the Custom CSS section of the column properties:
    mso-number-format:"\@"
    Refer snapshot here:
    http://i53.tinypic.com/a09kqv.jpg
    This will treat the data in the column as text while downloading to excel, hence retaining any leading or trailing spaces.
    Thanks
    Deva

  • Query for calculation in ALV Total

    HI All,
    I am using Sub_tot = "X" & do_sum="X" to get the subtotals & Totals for different columns Using REUSE_ALV_LIST_DISPLAY.
    I am calculating percentage in column "C" depending on result of Column "A" & Column "B", which is also achieved.
    My requirement is, Percentage in Total column to be calculated with use of TOTAL OF COLUMN "A" & TOTAL OF COLUMN "B". Because simply totaling all the values of percentage column will not work.
    Any Pointers will be helpful.
    Thanks In advance.
    Regards,
    Siddhesh Sanghvi.

    hi ,
       this is another example  for displaying the subtotals in many times ...
    report  zvg_alv_slist2                          .
    type-pools: slis.
    G L O B A L   I N T E R N  A L   T A B L E S
    data: gt_fieldcat type slis_t_fieldcat_alv,
          gs_layout   type slis_layout_alv,
          gt_events   type slis_t_event.
    data: it_sort type slis_t_sortinfo_alv ,
          wa_sort type slis_sortinfo_alv .
    data: gs_print type slis_print_alv.
    data: begin of it_sflight occurs 0,
            carrid     like sflight-carrid,
            connid     like sflight-connid,
            fldate     like sflight-fldate,
            price      like sflight-price,
            planetype  like sflight-planetype,
            seatsmax   like sflight-seatsmax,
            seatsocc   like sflight-seatsocc,
            paymentsum like sflight-paymentsum,
         end of it_sflight.
    *DATA: GI_SFLIGHT LIKE STANDARD TABLE OF ST_SFLIGHT.
    data: g_repid like sy-repid.
    data: gt_list_top_of_page type slis_t_listheader.
    data: v_total(5).
    start-of-selection.
      g_repid = sy-repid.
      perform init_fieldcat  using gt_fieldcat[].
      perform build_eventtab using gt_events[].
      perform build_comment  using gt_list_top_of_page[].
      perform get_data.
      perform set_layout using gs_layout.
    SORTING
      clear wa_sort.
      wa_sort-fieldname = 'CARRID'.
      wa_sort-up = 'X'.
      wa_sort-group = '*'.
      wa_sort-subtot = 'X'.
      append wa_sort to it_sort.
      clear wa_sort.
      wa_sort-fieldname = 'CONNID'.
      wa_sort-up = 'X'.
      wa_sort-group = 'UL'.
      wa_sort-subtot = 'X'.
      append wa_sort to it_sort.
    DISPLAY LIST
      call function 'REUSE_ALV_LIST_DISPLAY'
        exporting
          i_interface_check       = ' '
          i_callback_program      = g_repid
          i_callback_user_command = 'USER_COMMAND'
          is_layout               = gs_layout
          it_fieldcat             = gt_fieldcat[]
          it_sort                 = it_sort[]
          it_events               = gt_events
          is_print                = gs_print
        tables
          t_outtab                = it_sflight
        exceptions
          program_error           = 1
          others                  = 2.
      if sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      endif.
    *&      Form  INIT_FIELDCAT
    form init_fieldcat using    p_gt_fieldcat type slis_t_fieldcat_alv.
      data: ls_fieldcat type slis_fieldcat_alv,
            l_index type sy-tabix.
      data :rep like sy-repid.
      rep = sy-repid.
      call function 'REUSE_ALV_FIELDCATALOG_MERGE'
        exporting
          i_program_name         = rep
          i_internal_tabname     = 'IT_SFLIGHT'
          i_inclname             = rep
        changing
          ct_fieldcat            = gt_fieldcat
        exceptions
          inconsistent_interface = 1
          program_error          = 2
          others                 = 3.
      if sy-subrc <> 0.
        message id sy-msgid type 'S' number sy-msgno
             with sy-msgv1 sy-msgv2 sy-msgv3 sy-subrc.
      endif.
      sort gt_fieldcat by col_pos.
      loop at gt_fieldcat into ls_fieldcat.
        l_index = sy-tabix.
        if ls_fieldcat-fieldname = 'PRICE'.
          ls_fieldcat-do_sum = 'X'.
          ls_fieldcat-sp_group = 'X'.
          modify gt_fieldcat from ls_fieldcat index l_index .
        endif.
      endloop.
    endform.                    " INIT_FIELDCAT
    *&      Form  BUILD_EVENTTAB
    form build_eventtab using  p_gt_events type slis_t_event.
      data: ls_event type slis_alv_event.
      clear ls_event.
      ls_event-name = slis_ev_top_of_page.
      ls_event-form = 'XTOP_OF_PAGE'.
      append ls_event to p_gt_events.
      clear ls_event.
      ls_event-name = slis_ev_top_of_list.
      ls_event-form = 'XTOP_OF_LIST'.
      append ls_event to p_gt_events.
      clear ls_event.
      clear ls_event.
      ls_event-name = slis_ev_end_of_page.
      ls_event-form = 'XEND_OF_PAGE'.
      append ls_event to p_gt_events.
      ls_event-name = slis_ev_end_of_list.
      ls_event-form = 'XEND_OF_LIST'.
      append ls_event to p_gt_events.
      clear ls_event.
    endform.                    " BUILD_EVENTTAB
    *&      Form  BUILD_COMMENT
    form build_comment using   p_gt_list_top_of_page type slis_t_listheader.
      data: ls_line type slis_listheader.
      ls_line-typ = 'H'." = Header, S = Selection, A = Action
      ls_line-key = 'KEY'.
      ls_line-info = 'INFO'.
      append ls_line to p_gt_list_top_of_page.
    endform.                    " BUILD_COMMENT
    *&      Form  SELECTION
    form get_data..
    data: l_rows type i value 3.
    Read data from table SFLIGHT
      select carrid
             connid
             fldate
             price
             planetype
             seatsmax
             seatsocc
             paymentsum
         from sflight
         into table it_sflight.
        up to l_rows rows.
      sort it_sflight.
    endform.                    " SELECTION
    *&      Form  SET_LAYOUT
    form set_layout using  p_gs_layout type slis_layout_alv.
    *  P_GS_LAYOUT-F2CODE            = P_F2CODE.
      p_gs_layout-zebra          = 'X'.
      p_gs_layout-colwidth_optimize = 'X'.
      p_gs_layout-no_input          = 'X'.
      p_gs_layout-no_colhead        = space.
      p_gs_layout-totals_text       = 'Total Price'.
      p_gs_layout-subtotals_text    = 'Sub Total'.
      p_gs_layout-totals_only       = 'X'.
      p_gs_layout-key_hotspot       = 'X'.
      p_gs_layout-detail_popup      = 'X'.
      p_gs_layout-no_subtotals      = space.
      p_gs_layout-expand_all        = 'X'.
      p_gs_layout-group_buttons     = 'X'."space.
    endform.                    " SET_LAYOUT
          FORM XTOP_OF_PAGE                                             *
    form xtop_of_page.
    data : lv_page(5),
            lv_text(20).
      MOVE SY-PAGNO TO LV_PAGE.
      write:/  'X_TOP_OF_PAGE'.
    endform.                    "xtop_of_page
          FORM XTOP_OF_LIST                                             *
    form xtop_of_list.
      write:/  'X_TOP_OF_LIST'.
    endform.                    "xtop_of_list
          FORM XEND_OF_PAGE                                             *
    form xend_of_page.
      write:/  'X_END_OF_PAGE'.
    endform.                    "xend_of_page
          FORM XEND_OF_LIST                                             *
    form xend_of_list.
      write:/  'X_END_OF_LIST'.
      data : lv_page(5),
             lv_text(20).
      data : l_lines type i,
             l_line  type i.
      clear v_total.
      write sy-pagno to v_total left-justified.
    export v_total to memory id 'V_TOTAL'.
      do sy-pagno times.
        lv_page = sy-index.
        concatenate 'Page' lv_page 'of' v_total
             into lv_text separated by space.
        if sy-index = 1.
          read line 2 of page sy-index.
        else.
          read line 1 of page sy-index.
       endif.
        sy-lisel+60(20) = lv_text.
          modify current line .
      enddo.
    endform.                    "xend_of_list
          USER_COMMAND                                             *
    form user_command  using r_ucomm like sy-ucomm
                              rs_selfield type slis_selfield.
      case r_ucomm.
        when 'EXIT'.
          leave to screen 0.
        when '&IC1'.
          data: text(256),text1(6),text2(5).
          move rs_selfield-tabindex to text1.
          move rs_selfield-sumindex to text2.
          concatenate  'Double clicked on (field:'
                        rs_selfield-fieldname
                        'Value:'
                        rs_selfield-value
                        text1
                        text2
                        into text
                        separated by space.
          call function 'POPUP_TO_DISPLAY_TEXT'
            exporting
              textline1 = text.
      endcase.
    endform.                    "user_command
    regards,
    venkat.

  • MDX Query to Calculated member

    Hi All,
    I have a MDX query which works fine, when converting the query to Calculated member, I get the same result for all the rows of a dimension.
    select {[Measures].[Contents]} on 0,
    ([Dim Products].[Product Alias].[Product Alias].members,
    (filter ([Dim Products].[Product ID].members,
    instr(left([Dim Productss].[Product ID].currentmember.member_Key,3),'112')>0))) on 1
    from
    <<CubeName>>
    Calculated Member:
    SUM(filter ([Dim Products].[Product ID].members,
    instr(left([Dim Products].[Product ID].currentmember.member_Key,3),'112')>0),[Measures].[Contents])
    When I drag the dimension product, the calculated member showing the same result for all the products. Can anyone let me know the syntax error here.

    Hi SQL GUN,
    For me it works :
    WITH MEMBER [Last3MonthsInternetSales] AS 
    AGGREGATE
    LastPeriods(-3, ClosingPeriod([Date].[Calendar].[Month], [Date].[Calendar].[Month].&[2005]&[12])), 
    [Measures].[Internet Sales Amount]
    SET MySet AS
    {[Date].[Calendar].[Month].&[2005]&[09],
    [Date].[Calendar].[Month].&[2005]&[10],
    [Date].[Calendar].[Month].&[2005]&[11],
    [Date].[Calendar].[Month].&[2005]&[12],
    [Date].[Calendar].[Month].&[2006]&[01],
    [Date].[Calendar].[Month].&[2006]&[02]}
    SELECT
    [Measures].[Internet Sales Amount],
    [Last3MonthsInternetSales]
    } ON COLUMNS,
    MySet
    } ON ROWS
    FROM [Adventure Works]
    Are u sure your query is correct. I think you might have a [Fiscal Month Num of Year] too much in your (). I'm not sure, but are u dragging the correct level of hierarchy ? Also in the part ON ROWS you seem to take a lot of levels with you.
    Why for example take .allmembers when you only want the actual last 3 of your currentmember?
    Can u check again?

  • Query for calculating financialyear

    help me to write a query  which will check if the record createdon
    is within  the current financialyear  i.e. June 2014- July 2015
    RecordCreatedon
    logic
    2014-10-28
    yes
    2014- 12-15
    Yes
    2012- 01-19
    No
    Note  : query for calculating financialyear should be hardcoded .

    It looks like your sample data range is wrong "June 2014- July 2015"
    To get an idea, I consider June 2014 - May 2015 as financial year, try the below:
    create Table test_Table (RecordCreatedon date)
    Insert into test_table values('2014-10-28'),('2014- 12-15'),('2014- 06-01'),('2014- 05-30')
    ,('2015- 02-28'),('2015- 05-30'),('2015- 06-01')
    Select *,
    case when year(Dateadd(month,-5,RecordCreatedon) )=YEAR(getdate()) Then 'yes' else 'no' end Logic
    From test_Table
    Drop table test_Table

  • Writing an sql script to query a calculation view  and an attribute view inside a calculation view

    Hi,
    I was trying to query a calculation view with sql , and as one of the input parameters i was trying to give a query over an attribute view
    So my sql will look like this
    SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"('PLACEHOLDER' = ('$$ACCOUNT_ID$$', '1','$$CHECKLIST_ID$$',' SELECT CHECKLIST_ID FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5'));
    So as an input to $$CHECKLIST_ID$$   i wanted to give an id selected from checklist products table where products id is passed as an input
    but this is not working, i am getting syntax error at the $$CHECKLIST_ID$$ there i can only pass values like  $$CHECKLIST_ID$$, '1'
    Please help me to figure out which  is the correct syntax  i tried putting the sql statement to get the checklist_id in '' but it too didnot work

    I'm not sure you'll be able to do a SELECT subquery directly in the placeholder definition, but you can create another calc view (scripted) as a wrapper to your original calc view and use a scalar variable to pass the parameter over.
    Try this as the base code for your second calc view:
    var_id VARCHAR(10);
    BEGIN
         SELECT CHECKLIST_ID INTO :var_id FROM "MyApp"."CHECKLIST_PRODUCTS" WHERE PRODUCT_ID = 5;
         var_out = SELECT * FROM "MyApp.calculation_views::GET_CHECKLIST_FOR_ACCOUNT"
              (PLACEHOLDER."$$ACOUNT_ID" => 1, PLACEHOLDER."$$CHECKLIST_ID$$" => :var_id);
    END
    You could even create input parameters in the second Calc View for the Account Id & Product Id (which are currently hard coded in your code below).
    Best,
    Henrique.
    PS: avoid using SELECT * for the var_out in the scripted calc view. It's better, from a code maintenance perspective, to explicitly define the columns you're outputting.

  • Calculating percentages by date grouping in a Cross-tab report.

    I have created a monthly at glance dashboard, and I am having difficulty with the percentage breakdown.  I have the report grouped by date, and sorted by month with YTD total on the right.
    *The problem is all the rows with a percentage are calculating the same across the columns.  The YTD total is correct, but the totals for January and February are not 60%. 
    If I run the report for one month everything aligns, and in multiple months everything is correct with count summaries.
    Please let me know if anyone has any advice.

    Please see the crosstab expert window view requested below.
    Also, here is another screenshot of the crosstab in preview.  You will see that all sums with whole numbers are calculating and pulling correctly by month.  The sums with percentages are defaulting to the YTD across the row.  Thank you very much for your assistance.
    Joshua

  • Query a calculated column

    In a report I have used the source area to create a query that uses/creates calculated columns.
    Query:
    Select id, name, amount, percentage,
    amount * percentage AS CalCost
    from store
    where id = 3;
    Now I want to create another calculated column within that query using the created 'CalCost' column, similar to:
    Select id, name, amount, percentage,
    amount * percentage AS CalCost,
    amount - CalCost AS Difference,
    however, i get the ORA-0094 error stating that 'CalCost' is an invalid identifier.
    Is there any way to calculate this column without raising this error??

    963510 wrote:
    however, i get the ORA-0094 error stating that 'CalCost' is an invalid identifier.
    Is there any way to calculate this column without raising this error??Yes -- the alias isn't available from within the SELECT list. You'd have to redo the calc, i.e.:
    SELECT id, name, amount, percentage,
           amount * percentage AS CalCost,
           amount - (amount * percentage) AS Difference
    FROM   store
    WHERE  id = 3;Alternately, you could rewrite it as follows, where the alias would be available, but I see no reason to:
    SELECT id, name, amount, percentage, CalCost
           amount - CalCost AS Difference
    FROM   (SELECT id, name, amount, percentage,
                   amount * percentage AS CalCost,
                   amount - (amount * percentage) AS Difference,
            FROM   store
            WHERE  id = 3
           );

  • How can I display a letter grade in my gridview after calculating percentage into a hidden field in Visual Studio?

    For school I am working on an app using C# in visual studio that allows a student to enter their name, the number of points they earned and the points possible. When they click a submit button, the grade percentage is calculated in a hidden field and then
    the percentage and letter grade should spit out into the gridview. THe issue I am having is trying to figure out how to translate within the if statements regarding the percentage amount equalling whatever letter grade, and then spit that letter grade out
    into the gridview. Here is the code I have so far:
            protected void btnSubmit_Click(object sender, EventArgs e)
                SqlStudent.Insert();
                hdnGradePercent.Value = (((int.Parse("txtPointsEarned.Text")) / (int.Parse("txt.PointsPoss.Text")) * 100)).ToString();
                if ((int.Parse(hdnGradePercent.Value) >= 0) & ((int.Parse(hdnGradePercent.Value) <= 59)))
    (this is where I am having trouble. I can't figure out how to get the letter grade and percent to spit out into the   gridview.)
                else if ((int.Parse(hdnGradePercent.Value) >= 60) & ((int.Parse(hdnGradePercent.Value) <= 69)))
                else if ((int.Parse(hdnGradePercent.Value) >= 70) & ((int.Parse(hdnGradePercent.Value) <= 79)))
                else if ((int.Parse(hdnGradePercent.Value) >= 80) & ((int.Parse(hdnGradePercent.Value) <= 89)))
                else if ((int.Parse(hdnGradePercent.Value) >= 90) & ((int.Parse(hdnGradePercent.Value) <= 100)))
    Any help would be greatly appreciated! I've been stuck on this for hours and I"m losing my mind!!

    Please post ASP.NET questions in the ASP.NET forums (http://forums.asp.net ).

  • Query field calculation based on a characteristic field

    Hi
    I have a req wherein the query has a field "Balance". Now here the value of the Balance field is calculated based on another characteristic "0bal_flag". 0bal_flag has values "X" or blank. The 0bal_flag is actually a attr of 0gl_account and i have it as a nav attr in my cube.
    The calculation goes like this....
    If 0bal_flag = 'X' then "Balance" = balance (there is a balance field in underlying infoprovider)
    else "Balance" = Debit -credit (these fields are also there in underlying infoprovider....)
    So how do i achieve this...?
    Since 0bal_flag is a char I cannot use it directly in a formula....
    Thanks
    Gaurav

    Hi Gaurav,
    Create a replacement path formula variable on the 0bal_flag with evaluate as boolean checked, you will get the values 1 when flag is X and 0 when the flag is initial, now you can use this 'formula variable' in the formula
    ((0bal_flag==1)balance)+((0bal_flag==0)(debit-credit))
    hope this helps,
    Rk.

  • HANA, Aggregations and calculating percentages

    I have a table containing user-role assignments, e.g. the table contains tuples of the form (userA, roleA), (userA, roleB). Now, I would like to get an overview on how the distribution of users across roles. I would like to get the following overview.
    role
    COUNT DISTINCT user
    percentage
    roleA
    5
    5/15 * 100 = 33,3 %
    roleB
    8
    53,3 %
    roleC
    10
    66,6 %
    Total
    15
    Using SAP HANA Studio, I created a Calculated View and count the number of distinct users with a counter. However, how to compute the totals (note that this is not the sum of distinct users per role) and how to compute then the percentages?
    Thanks!

    OK, totals are now computed by modeling the following two aggregations:
    1. count distinct users per role
    2. count distinct users in the table
    Then the two aggregations are joined.
    A new problem pops-up: I divide the two different counts in a calculated column or calculated attribute. Whatever I try, the result of dividing two integers is 0. What should I do?

  • Nested CASE Statements in my SELECT of Query not calculating correctly

    Hi - Am doing simple query to calculate statistics on students per course, the WHERE includes a parameter for Academic Year, so need If Academic Year = x then calculate age in the 1st Sept of that Year, then count number of 19Yrs&Over. Have included my successful lines for sum of other data, in my CASE the calculations are not distinguishing whether age is over or under 19 just counting all. Presume is problem with Date calculation or CASE?? Runs without error..I'm guessing I can nest a CASE?!
    Many thanks!
    SELECT ......
    various fields bought through then
    count(p.PERSON_CODE) All_Enrolments,
    sum(DECODE(ru.FES_PROGRESS_CODE,'ACT',1,0)) Active,
    sum(DECODE(ru.FES_PROGRESS_CODE,'WNS',1,0)) NonStarter,
    sum(DECODE(ru.FES_PROGRESS_CODE,'WTH',1,0)) Withdrawn,
    sum(DECODE(ru.FES_PROGRESS_CODE,'TRN',1,0)) Transfers,
    sum(DECODE(la.completion,'2',1,0)) Completed,
    sum(DECODE(la.outcome,'1',1,0)) Achieved,
    sum(DECODE(p.sex,'F','1','0')) Female,
    sum(DECODE(p.sex,'M','1','0')) Male,
    SUM(
    CASE
    WHEN uio.CALOCC_OCCURRENCE_CODE='04'
    THEN
    CASE
    WHEN ((to_date('01-08-2004','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
    THEN '0'
    ELSE '1'
    END
    WHEN uio.CALOCC_OCCURRENCE_CODE='05'
    THEN
    CASE
    WHEN ((to_date('01-08-2005','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
    THEN '0'
    ELSE '1'
    END
    WHEN uio.CALOCC_OCCURRENCE_CODE='03'
    THEN
    CASE
    WHEN ((to_date('01-08-2003','dd-mm-yyyy')-to_date(p.date_of_birth,'dd-mm-yyyy'))/365.25)<'19'
    THEN '0'
    ELSE '1'
    END
    ELSE '0'
    END ) Over19sInc19
    FROM .......

    you can use this formula to check on the age:
    TRUNC(MONTHS_BETWEEN(to_date('01-08-2004','dd-mm-yyyy'),to_date(p.date_of_birth,'dd-mm-yyyy'))/12)hope this helps.

  • OBIEE 11G - problem with calculating percentage

    Hi,
    I have a problem with calculating a percentage....
    I have a 2 measures Success and Failure
    where Success is a count(Response_key)
    Failure is a count(failure_key)
    I want Success/(Success+Failure) * 100
    I am getting this value as a 0
    Infact any column I take from the subject area and say count of that column and divide it by any integer say count(column1)/5 ,Say count of that column1 is 132 Eg: 132/5 , Its showing this value as 26.00 when I put decimal value to 2 , but it is 26.4...It is avoiding decimal values .
    So in my case success/(success+failure) in which Dr is greater than Nr . Since we get the value as 0.something . It is showing 0 value
    So , 0*100 it is showing me as 0%
    Can anyone please help me on this ??
    --Siri                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Yes, you need to put cast in numerator alone to get the resultant output in double.
    You can mark the post as Correct since your issue is resolved now.
    Thanks

Maybe you are looking for