Average for each contragentid

Hi all! This code works fine, it returns proper average value for contragentid = 1. So, correct result is LUAHPER = 14996837,94
But when I add values for contragentid = 2 (see commented strings), my statement returns incorrect result LUAHPER = 5497801,81
How do I improve my code in order to calculate average for each contragentid?
with t as (
select to_date('12.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('14.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('15.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('16.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15274795.50 as luah, 215274795.50 as lusd from dual
union all
select to_date('17.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15431807.40 as luah, 215431807.40 as lusd from dual
union all
select to_date('18.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15480730.00 as luah, 215480730 as lusd from dual
union all
select to_date('21.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15480730.00 as luah, 215480730 as lusd from dual
/*union all
select to_date('12.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('14.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('15.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('16.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215274795.50 as luah, 215274795.50 as lusd from dual
union all
select to_date('17.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215431807.40 as luah, 215431807.40 as lusd from dual
union all
select to_date('18.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215480730 as luah, 215480730 as lusd from dual
union all
select to_date('21.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215480730 as luah, 215480730 as lusd from dual*/
select contragentid, sum(luahper) / cnt as luahper
from (
select contragentid, (lead(arcdate,1,date '2011-03-20' + 1) over(order by arcdate) - arcdate) * luah luahper,
date '2011-03-20' - date '2011-03-13' + 1 cnt
from (
select arcdate, contragentid, luah, lusd
from
t
where arcdate > date '2011-03-13'
and arcdate <= date '2011-03-20'
union all
select greatest(arcdate,date '2011-03-13'),
contragentid, luah, lusd
from
t
where arcdate = (select max(arcdate) from
t
where arcdate <= date '2011-03-13')
where contragentid = 1
group by contragentid, cnt

My code works fine, help me insert in proper way
@prompt('b. begin date:','D',,Mono,Free,Persistent,,User:0)
@prompt('a. end date:','D',,Mono,Free,Persistent,,User:0)
instead of '2011-03-13', '2011-03-20'
with t as (
select to_date('12.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('14.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('15.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,14275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('16.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15274795.50 as luah, 215274795.50 as lusd from dual
union all
select to_date('17.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15431807.40 as luah, 215431807.40 as lusd from dual
union all
select to_date('18.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15480730.00 as luah, 215480730 as lusd from dual
union all
select to_date('21.03.2011','dd.mm.yyyy') as arcdate, 1 as contragentid,15480730.00 as luah, 215480730 as lusd from dual
union all
select to_date('12.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('14.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('15.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,214275303.54 as luah, 214275303.54 as lusd from dual
union all
select to_date('16.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215274795.50 as luah, 215274795.50 as lusd from dual
union all
select to_date('17.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215431807.40 as luah, 215431807.40 as lusd from dual
union all
select to_date('18.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215480730 as luah, 215480730 as lusd from dual
union all
select to_date('21.03.2011','dd.mm.yyyy') as arcdate, 2 as contragentid,215480730 as luah, 215480730 as lusd from dual
SELECT contragentid, SUM(luahper) / cnt AS luahper, SUM(lusdper) / cnt AS lusdper
  FROM (SELECT contragentid
              ,(lead(arcdate, 1, DATE '2011-03-20' + 1) over(PARTITION BY contragentid ORDER BY arcdate) - arcdate) * luah luahper
              ,(lead(arcdate, 1, DATE '2011-03-20' + 1) over(PARTITION BY contragentid ORDER BY arcdate) - arcdate) * lusd lusdper
              ,DATE '2011-03-20' - DATE '2011-03-13' + 1 cnt
          FROM (SELECT arcdate, contragentid, luah, lusd
                  FROM t
                 WHERE arcdate > DATE '2011-03-13'
                   AND arcdate <= DATE '2011-03-20'
                UNION ALL
                SELECT greatest(arcdate, DATE '2011-03-13')
                      ,contragentid
                      ,luah
                      ,lusd
                  FROM t
                 WHERE arcdate = (SELECT MAX(arcdate) FROM t WHERE arcdate <= DATE '2011-03-13')
GROUP BY contragentid, cnt

Similar Messages

  • MDX Query for Average customer first sale amount for each year

    Hello,
    I new to MDX, and I am looking to build a query that would get all the first sale amount for the customes and average that.  The intent is to use find an average each year.   I am looking to use this against the adventure works database.   
    I am not sure exatcly how to start this .  Any help is much appreciated.
    J

    Hi,
    I'll do it in several stages.
    let's first define an ordered set of date/sale to one customer over all periods:
    SELECT
    {[Measures].[Internet Sales Amount]} ON 0
    NonEmpty
    [Date].[Calendar].[Date]
    [Customer].[Customer].&[15561]
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customter].&[15561]
    ) ON 1
    FROM [Adventure Works];
    we retain the first line of the result set  with item(0):
    SELECT
    {[Measures].[Internet Sales Amount]} ON 0
    NonEmpty
    [Date].[Calendar].[Date]
    [Customer].[Customer].&[15561]
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].&[15561]
    ).Item(0) ON 1
    FROM [Adventure Works];
    next, for each year we define a measure that will retain the first sale for each customer
    (I  limit the customer set to the first 2000)
    WITH
    MEMBER [Measures].[Mymeasure 2006] AS
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2006]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    MEMBER [Measures].[Mymeasure 2007] AS
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2007]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    SELECT
    [Measures].[Mymeasure 2006]
    ,[Measures].[Mymeasure 2007]
    } ON 0
    ,NON EMPTY
    Head
    [Customer].[Customer].[Customer]
    ,2000
    ) ON 1
    FROM [Adventure Works];
    We then take the average for each year:
    WITH
    MEMBER [Measures].[AVG cust first sale 2006] AS
    Avg
    Head
    [Customer].[Customer].[Customer]
    ,2000
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2006]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    MEMBER [Measures].[AVG cust first sale 2007] AS
    Avg
    Head
    [Customer].[Customer].[Customer]
    ,2000
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2007]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    SELECT
    [Measures].[AVG cust first sale 2006]
    ,[Measures].[AVG cust first sale 2007]
    } ON 0
    FROM [Adventure Works];
    Philip,

  • Health app: bug in daily average for sleep in year view?

    I've manually entered sleep time for everyday since August 2014 in the Health app (on iOS 8, on an iPhone 6).
    In Day, Week, and Month view, the daily average seems correct (resp. 7h49, 7h09, 7h09).
    But it is obviously wrong in the Year view (12h36mn).
    Also the graph in the Year view is wrong. (The bar for August is twice as high as the one for October for instance.)
    (I've check -3 times- that these manually entered data were correct.)
    Does anybody experience the same problem?
    Or as any idea what the bars, in the Year Graph, are supposed to represent? (daily average for each month? or total sum of sleep time for the month?)
    Thanks in advance!
    Antoine

    The Health App really serves as a conduit between a variety of other apps that wouldn't ordinarily be able to talk to each other. The App Store has a section for apps that work with Health to be able to sync data.
    You can submit feedback to Apple here:
    http://www.apple.com/feedback
    Don't stress to much if you can't find a section dedicated to Health. Pick something under "iPhone" and just make sure you explain it well.

  • Modifying the 'Grade Book' template to have a Report for each student

    The grade book template looks like it could save me from buying Bento 2 and look prettier in the process. However, I might need to get some applescript help.
    The default template has a Report page, and it includes one student. The included comment says to change the students name to change the values.
    I want to have one of those reports for each student automatically generated and printable so that I can give them to the students at the end of the term.
    Obviously, I don't want to generate each report myself (320 students ... not a fun way to spend a day). Applescript seems like the solution, but I don't know how to use it.
    Can anyone lend a hand?

    Not seeing exactly what you want it's hard to be sure what solution may work - fortunately there are others here that know far more than me.
    I don't know how charts and graphs are moved to Pages, but if it cut and paste, I suspect it would be unlikely that you could do it with charts or graphs based on individual students. If it can be done with a mail merge, maybe it could.
    But I'm thinking a different approach may be possible if the only charts or graphs you use are to show the class info and mail merge the individual student data.
    Let me see if I can explain what I'm thinking of:
    You mail merge info like scores for each test and/or just the average of each grade category, plus the overall average and personal comments.
    As part of the pages document that is the same for every student, you could put the charts or graphs in for the class as a whole. For example, if you wanted the student to see the class average for each test to compare to their own score, you could have a graph for that CLASS info and then they could look at their mail merged info to see how they compared. It just wouldn't be part of the same graph.
    I think this would let you have the same info as in the template, but structured a bit differently.
    You may also be able to reproduce everything from individual tables into one big table - more than just normal summary info - and work from that. Basically it would be a table of just formulas pulling in from the other tables.
    This is something I'm looking at for some of my projects, but I haven't worked out the details yet.
    Good luck.

  • How to measure signal duration and statistics for each pulse

    The attached vi has data for the maximum value of six different cutting tools while machining a part for 48000+ consecutive cycles. How would I measure the length of time each tool was used before being changed??(when profile makes a large negative transition.) Since the first three tools are related to the same holes in the part, I would also like to be able to get statistics(average) for each individual peak to see how the life of one tool affects the other tools. I am not sure if I need to do some more averaging or a differentiation to detect slope change points?? The peak detection vi's did not work real well since the peaks are not a constant value each time. This is a version 7 file.
    Attachments:
    display_tooling_data_max_values.vi ‏1643 KB

    Judging by your graphs, what you need is a differential operation:
    Break the wire going from the MEAN output to the graph.
    Insert a TIME DOMAIN MATH block (from the ARITHMETIC AND COMPARISON palette)
    Make sure it's set for DIFFERENTIAL.
    Wire the output to your graph.
    See all those negative spikes? That's the transitions in your data. Put a threshold on those, and you'll determine where the changes are.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks

  • Stock of material and moving average price for each valuation type

    Hi
    Is anybody aware of any standard report which will show the stock of material and moving average price of the material for each valuation type.
    M5BL is one report but would like to check if there is any other report.
    Regards
    Vaibhav Mahajan

    Hi,
    Check MB52, select 'Display batch stock' option.
    Batch is nothing but your valuation type.
    You can see those details there.
    Regards,
    Piyush

  • Return average of time interval in each hour for each day

    I am reading from a database and the data is stored like this
    Date................ Hour........Hour Interval..........Price
    2010/07/01.........1...................1.....................x
    2010/07/01.........1...................2.....................x
    2010/07/01.........1...................3.....................x
    2010/07/01.........1...................4.....................x
    2010/07/01.........1...................5.....................x
    2010/07/01.........1...................6.....................x
    2010/07/01.........1...................7.....................x
    2010/07/01.........1...................8.....................x
    2010/07/01.........1...................9.....................x
    2010/07/01.........1...................10...................x
    2010/07/01.........1...................11...................x
    2010/07/01.........1...................12...................x
    2010/07/01.........2...................1.....................x
    2010/07/01.........2...................2.....................x
    2010/07/01.........2...................3.....................x
    2010/07/01.........2...................4.....................x
    How would I write an sql statement to get the average for the price for each hour. The average should take the average of all the prices in the interval from 1 to 12
    Any suggestions
    Edited by: user13353366 on Jul 1, 2010 11:55 AM

    Hi,
    Welcome to the forum!
    Whenever you have a question, it helps if you post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data. No doubt you have a perfectly clear idea of what your data is, and what results you want, but other people are likely to make bad assumptions from just looking at a description of the problem. For example, are date and hour one colum or two? What role does hour_interval play in this problem?
    So, in addition to a description of the data and the probelm, post a specific example, like this for the data:
    CREATE TABLE     table_x
    (     dt          DATE
    ,     hour_interval     NUMBER (2)
    ,     price          NUMBER
    INSERT INTO table_x (dt, hour_interval, price) VALUES (TO_DATE ('2010/07/01 01', 'YYYY/MM/DD HH24'),   1,   1);
    INSERT INTO table_x (dt, hour_interval, price) VALUES (TO_DATE ('2010/07/01 01', 'YYYY/MM/DD HH24'),   2,   1.1);
    INSERT INTO table_x (dt, hour_interval, price) VALUES (TO_DATE ('2010/07/01 02', 'YYYY/MM/DD HH24'),   4,   9);
    INSERT INTO table_x (dt, hour_interval, price) VALUES (TO_DATE ('2010/07/01 02', 'YYYY/MM/DD HH24'),  13,   9.9);and like this for the results you want from that same data:
    HR             AVG_PRICE
    2010/07/01 01       1.05
    2010/07/01 02          9If those happens to be the results you would want from that data, then, as Lkbrwn said, AVG and GROUP BY can get them for you, like this:
    SELECT       TRUNC (dt, 'HH')     AS hr
    ,       AVG (price)          AS avg_price
    FROM       table_x
    WHERE       hour_interval     BETWEEN      1
                   AND     12
    GROUP BY  TRUNC (dt, 'HH')
    ORDER BY  hr
    ;

  • Need to display average percent of spend for each vendor in top ten

    Hi Friends,
                 I have to design a query where  I need to display top ten vendors and for that top ten vendors  need to sum the AMT and I have to calculate the average percentage of each vendor in top ten list from the total. Based and the specified range have to create exceptions.
    I am able to display top ten vendors. Now the problem is unable to calculate total of top ten vendors and average percentage of each vendor from total. like the below
         spend     Spend Ratio     Spend Percentage     
    vendor 4     121987     0.299181333     30%     80% is an A
    vendor 10     101103     0.247961917     55%     
    vendor 8     98723     0.242124806     79%     
    vendor 9     23456     0.05752742     85%     80-95% is a B
    vendor 5     12345     0.030276944     88%     
    vendor 6     10540     0.02585006     90%     
    vendor 7     9906     0.024295132     93%     
    vendor 3      9903     0.024287774     95%     95-100% is a C
    vendor 2     9899     0.024277964     98%     
    vendor 1     9874     0.02421665     100%     
    Total     407736               
    Please, suggest me to proceed further.
    Thank You.
    Manjula

    Hi manjula
    In order to get total for any key figure .... for that key figure at the query level in the  calculation tab there will be one box like calculate result as there u give sum or average accroding to ur purpose... then it will display the total or average accordingly....
    the key figure when used average for result shows average of all record conrtibutions but
    In order to display the  percentage of each vendor from total u can use
    Percentage Share of Result (%CT)
    %CT<Operand>
    Specifies how high the percentage share is in relation to the result. The result
    means the result of aggregation at the next level (interim result).
    %CT Incoming Orders specifies the share of incoming order values of each
    individual characteristic value (for example of each customer) in relation to
    the characteristic's result (for example, customer of a division).
    Regards
    vamsi

  • Show DataTips for each series

    Is there a way to customize the DataTips for each series in a
    chart? I have a column chart that has a line series in it. The
    columns display actual data, but the line shows an average.
    Currently the datatips are set to show the column chart values,
    even when a user hovers over a line chart datatip. Is there any way
    to have the datatips for the lineseries display the lineseries
    data?
    I know I could create a DataTipFormatter that included both
    the column data and the line data at the same time, but I would
    like them separate.

    Adobe Newsbot hopes that the following resources helps you.
    NewsBot is experimental and any feedback (reply to this post) on
    its utility will be appreciated:
    L (Flex 3):
    The LineChart control represents a data series as points
    connected by a continuous .... whose contents are highlighted when
    a user moves the mouse over it.
    Link:
    http://livedocs.adobe.com/flex/3/langref/all-index-L.html
    Is it possible to use data labels with line chart? - Flex
    India:
    Feb 27, 2008 ... I want to create a line chart which shows
    all the labels, regardless of the mouse pointer.
    showAllDataTips=true works but the result is
    Link:
    http://groups.google.com/group/flex_india/browse_thread/thread/709c9651ad7c9062
    mx.charts.LineChart (Flex 2.0.1 Language Reference):
    Specifies the distance, in pixels, that Flex considers a data
    point to be under the mouse pointer when the mouse moves around a
    chart.
    Link:
    http://livedocs.adobe.com/flex/201/langref/mx/charts/LineChart.html
    Print Page - Disable datatip but keep mouse event on line
    chart:
    Flex and ActionScript 3.0 => Flex Charting => Topic
    started by: Sablotron on 29 July 2008, ... Title: Disable datatip
    but keep mouse event on line chart
    Link:
    http://www.flexdeveloper.eu/forums/index.php?action=printpage;topic=895.0
    [#FLEXDMV-1683] dataTipFunction for LineChart is not executed
    when:
    Mar 12, 2008 ... Set dataProvider for LineChart with one
    datapoint 3. Set a dataTipFunction for the LineChart Actual
    Results: Datatip does not show on mouse
    Link:
    http://bugs.adobe.com/jira/browse/FLEXDMV-1683
    Disable datatip but keep mouse event on line chart |
    flexdeveloper:
    Aug 6, 2008 ... Disable datatip but keep mouse event on line
    chart, help forums for developers working with ActionScript 3.0,
    Flex 3, Flash CS3.0, and AIR.
    Link:
    http://www.flexdeveloper.eu/forums/index.php?topic=895.msg2716
    Disclaimer: This response is generated automatically by the
    Adobe NewsBot based on Adobe
    Community
    Engine.

  • 1099 Printout 2 copies for each vendor

    SAP Gurus,
    I am trying to run 1099 forms, I am using tcode S_P00_07000134 - Generic Withholding Tax Reporting.
    When I run program I only see Copy B, which is for the vendors records, I will still need Copy A in order to send to Federal. Does anyone knows the process? We implemented all the OSS notes possible related for 2008, but it appears that SAP scanned double copies in one page both copies are Receipient.
    When I run tcode I don't even get form 1096 which is part of 1099 process.
    Is anyone having the same issue?
    Edited by: Frank on Jan 28, 2009 10:49 PM

    Hi manjula
    In order to get total for any key figure .... for that key figure at the query level in the  calculation tab there will be one box like calculate result as there u give sum or average accroding to ur purpose... then it will display the total or average accordingly....
    the key figure when used average for result shows average of all record conrtibutions but
    In order to display the  percentage of each vendor from total u can use
    Percentage Share of Result (%CT)
    %CT<Operand>
    Specifies how high the percentage share is in relation to the result. The result
    means the result of aggregation at the next level (interim result).
    %CT Incoming Orders specifies the share of incoming order values of each
    individual characteristic value (for example of each customer) in relation to
    the characteristic's result (for example, customer of a division).
    Regards
    vamsi

  • Display average for line items

    I have a query with a fixed row structure basically line items restricting on specific cost centers. I have my column structure where my key figures are alone with date restrictions, etc. Part of my query requires the user to specify the date interval for the data they want to see: Production date: 8/01/2008 - 8/12/2008 for example, but instead of the total for that date range for each line item in my row structure, they want to see the month-to-date average of the production for that time period. I have tried to do the option of Average for all values under the local calculations, but it still gives me the total, so I'm assuming that only applies to the result rows. The option for aggregation is grayed out. Temporarily, I have given them an input variable to enter 12 for the number of days and done the division in a formula, but I don't want to continue to have to do that if there is a better way.

    We have implemented something similar using formula variables to calculate the number of days between an input date range interval. Ex. ZPRDDATE is the input variable they enter 8/1/2008 - 8/31/2008
    Have two formula variables which are derived from ZPRDDATE in auser exit:
    Start Date = From value of ZPRDDATE (8/1 in this case)
    End Date = To Value of ZPRDDATE (8/12 in this case)
    Build 3 formulas in your query:
    Start Date = Start Date variable
    End Date = End Date Variable
    Diff Daus = End Date - Start Date
    The n you can calculate the avg in a formula

  • Different Year Ends For Each Venture in JVA

    Hi Guys,
    Can we define different year ends for each venture we create in Joint Venture Accounting Module of SAP IS Oil and Gas Solution. If yes how can we ? transaction code or path needed.

    This may be a good start. Display by Month Year the Average and Sum Dates between Start and Stop by Project.
    SELECT      CAST    (
            (CAST(MONTH(Start) AS varchar(2)) + '/01/' + CAST(YEAR(Start) AS varchar(4)))
            AS DateTime
        AS DatePeriod,
        AVG(DateDiff(day, Start, Stop)) AS AverageDaysToClose,
        SUM(DateDiff(day, Start, Stop)) AS SumTotalDaysToClose,
        Name
    FROM     Projects
    GROUP BY CAST    (
            (CAST(MONTH(Start) AS varchar(2)) + '/01/' + CAST(YEAR(Start) AS varchar(4)))
            AS DateTime
        Name
    ORDER BY DatePeriod, Name

  • Problem to calculate the coherence (using NetworkFunction-VI) with only 1 row of data for each, the stimulus and response input

    Hello,
    I am trying to calculate the coherence of a stimulus and response
    signal using the Network Functions (avg) VI's. The problem is that I
    always get a coherence of "1" at all frequencies. This problem is
    already known (see KnowledgeBase document: Why is the Network Functions (avg) VI's Coherence Function Output "1"?).
    My trouble is that the described solution (-> the stimulus and response input matrices need to have at least two rows to get non-unity coherence values) doesn't help me much, because I only have one array of stimulus data and one array of response values.
    Thus, how can I fullfil the 'coherence-criteria' to input at least two rows of data each when I just have one row of data each?
    Any hint or idea is very much appreciated. Thanks!
    Horst

    With this weird board layout, I'm not sure whether you were asking me, but, on the assumption that you were, here goes:
    I found no need to use the cross-power spectrum and power spectrum blocks
    1... I was looking for speed.
    2... I already had the component spectral data there, for other purposes. From that, it's nothing but addition and multiplication.
    3... The "easy" VIs, assume a time wave input, as I recall. Which means they would take the same spectrum of the same timewave several times, where I only do it once.
    I have attached PNGs of my code.
    The PROCESS CHANNEL vi accepts the time wave and:
    1... Removes DC value.
    2... Integrates (optional, used for certain sensors).
    3... Windows (Hanning, etc. - optional)
    4... Finds spectrum.
    5... Removes spectral mirrors.
    6... Scales into Eng. units.
    7... From there, you COULD use COMPLEX-TO-POLAR, but I don't care about the phase data, and I need the MAG^2 data anyway, so I rolled my own COMPLEX-TO-MAG code.
    The above is done on each channel. The PROCESS DATA vi calls the above with data for each channel. The 1st channel in the list is required to be the reference (stimulus) channel.
    After looping over each channel, we have the Sxx, Syy, and Sxy terms. This code contains some averaging and peak-picking stuff that's not relevant.
    From there, it's straightforward to ger XFER = Sxy/Sxx and COHERENCE = |Sxy|^2 / (Sxx * Syy)
    Note that it uses the MAGNITUDE SQUARED of Sxy. Again, if you use the "easy" stuff, it will do a square-root operation that you just have to reverse - it is obtained faster by the sum of the squares of the real and imag parts.
    Hope this helps.
    Steve Bird
    Culverson Software - Elegant software that is a pleasure to use.
    Culverson.com
    Blog for (mostly LabVIEW) programmers: Tips And Tricks
    Attachments:
    ProcessChannel.png ‏25 KB

  • Select last value for each day from table

    Hi!
    I have a table that stores several measures for each day. I need two queries against this table and I am not quite sure how to write them.
    The table stores these lines (sample data)
    *DateCol1                 Value       Database*
    27.09.2009 12:00:00       100           DB1
    27.09.2009 20:00:00       150           DB1
    27.09.2009 12:00:00       1000          DB2
    27.09.2009 20:00:00       1100          DB2
    28.09.2009 12:00:00       200           DB1
    28.09.2009 20:00:00       220           DB1
    28.09.2009 12:00:00       1500          DB2
    28.09.2009 20:00:00       2000          DB2Explanation of data in the sample table:
    We measure the size of the data files belonging to each database one or more times each day. The value column shows the size of the database files for each database at a given time (European format for date in DateCol1).
    What I need:
    Query 1:
    The query should return the latest measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009        150          DB1
    27.09.2009       1100          DB2
    28.09.2009        220          DB1
    28.09.2009       2000          DB2Query 2:
    The query should return the average measurement for each day and database. Like this:
    *DateCol1       Value      Database*
    27.09.2009       125          DB1
    27.09.2009      1050          DB2
    28.09.2009       210          DB1
    28.09.2009      1750          DB2Could someone please help me to write these two queries?
    Please let me know if you need further information.
    Edited by: user7066552 on Sep 29, 2009 10:17 AM
    Edited by: user7066552 on Sep 29, 2009 10:17 AM

    For first query you can use analytic function and solve it.
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select dt, val, db
      from (
    select row_number() over(partition by trunc(dt), db order by dt) rno,
           count(*) over(partition by trunc(dt), db) cnt,
           t.*
      from t)
    where rno = cntFor second you can just group by
    with t
    as
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss') dt,       100 val,           'DB1' db from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       150,           'DB1' from dual union all
    select to_date('27.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1000,          'DB2' from dual union all
    select to_date('27.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1100,          'DB2' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       200,           'DB1' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       220,           'DB1' from dual union all
    select to_date('28.09.2009 12:00:00', 'dd.mm.yyyy hh24:mi:ss'),       1500,          'DB2' from dual union all
    select to_date('28.09.2009 20:00:00', 'dd.mm.yyyy hh24:mi:ss'),       2000,          'DB2' from dual
    select trunc(dt) dt, avg(val) val, db
      from t
    group by trunc(dt), db
    order by trunc(dt)

  • Calculate avg for each record

    Hello,
    what i want is: i have a table
    SCHOOLBOY (id, first_name, last_name, ...)
    and another table
    MARKS (id, schoolboy_id, discipline_id, mark, mark_type). a schoolboy
    on a discipline (e.g. Maths), a schoolboy can have more marks. i wanna calculate the avg of the marks, but for each schoolboy. then, for example i wanna generate a report containing the first name, last name of the schoolboy, and near, the average of the marks.
    how can i calculate the avg of all marks for each schoolboy ?
    Thanks!
    Edited by: Roger22 on 06.06.2009 01:43

    ok, so i post a working case
    create table schoolboys(
    id  numeric(10)     not null,
    first_name   varchar2(50)    not null,
    last_name    varchar2(50),
      CONSTRAINT sch_pk PRIMARY KEY (id)
    insert into schoolboys values (1, 'John','Michael');
    insert into schoolboys values (2, 'Sorin','Wayne');
    insert into schoolboys values (3, 'Aaa','Bbb');
    insert into schoolboys values (4, 'ccc','ddd');
    create table marks(
    id  numeric(10)     not null,
    schoolboy_id integer not null,
    discipline_id integer not null,
    mark number(2) not null,
    mark_type char(1) not null default 'O',
       constraint fk_schoolboyid foreign key(schoolboy_id) references schoolboys(id),
       CONSTRAINT pk_marks PRIMARY KEY (id)
    insert into marks values (1, 1, 4, 10,'O');
    insert into marks values (2, 1, 4, 9,'O');
    insert into marks values (3, 1, 4, 8,'O');
    insert into marks values (4, 3, 2, 10,'O');
    insert into marks values (5, 3, 2, 9,'O');so i created the tables, also i inserted some values. in my example i wanna calculate the avg of the marks for each schoolboy (in this case for 1 and 3) on a specific discipline_id. in that table i can have many schoolboys with many marks at more disciplines. i wanna calculate, for each schoolboy the avg of the marks on a specific discipline.
    Thank you

Maybe you are looking for

  • Overheating issue with 4870 crossfirex setup / i7 platform

    hi there my rig: MSI X58pro-e bios 8.5(latest) corei7 920 2.66GHz twinMOS 3x2GB DDR3 1333 Tri ch 2 R4870-T2D1G 4 PIPE Fan (non reference) @ crossfirex mode 1HDD 1DVD drive Gigabyte superb 720 psu(80+ , 3 rails of 12v 18A,18A,18A . 610 true wattage,42

  • The Sender agreement has another channel

    Hi all you guys I have the following problem: I create a scenario RFC --> XI --> JDBC  in wich I configure the sender  agreement: SERVICE : SYSTEM A INTERFACE: INTERFACE A COMM CHANNEL: cc_sender_RFC_A THEN I create another cc by security issues with

  • FND Attachements Conversion

    Hi, I m working on Attachments conversion from 11i to r12, I m getting Attachment in BLOB column from custom table xx_attch_data. I have seen a sample in online which has below part before calling fnd_attached_documents_pkg. Since I m getting Attachm

  • Internal software error:./vobulator\blockplanner\blockplanner.cpp,line538

    I received this error message on my first attempt at burning a DVD. It was in the transcoding process on the fourth video clip. I shut down and tried again with the same result. In checking the forum, I see that others have experienced nearly the sam

  • Remove package from Distribution Point

    I have been fighting with an OS deployment for the last day. The log was showing it was unable to find the package p0100001 which was my boot image. I eventually got it working as I failed to configure my boundary correctly. But it got me wondering..