ADF or SQL: Find Peaks Of Data By Values And Sum Over Time Period

Holomew 26 Reputation points
2021-07-12T00:16:40.883+00:00

Looking for an ADF solution or a SQL query/SP (or maybe even Databricks if necessary): I'm looking to find the sum of peak(s) of given values by type over a time period. Furthermore, if the peak doesn't have a downward trend during the given time period, it should not be counted.

The data, for example:

Type Amount Date
AAA 10 2021-07-11
AAA 15 2021-07-11
AAA 20 2021-07-11
AAA 25 2021-07-11 *Need this peak
AAA 20 2021-07-11
AAA 15 2021-07-11
AAA 10 2021-07-11
AAA 15 2021-07-11
AAA 20 2021-07-11
AAA 25 2021-07-11
AAA 30 2021-07-11 *Need this peak added to previous peak
AAA 25 2021-07-11
AAA 20 2021-07-11
AAA 15 2021-07-11
AAA 10 2021-07-11
BBB 10 2021-07-11
BBB 20 2021-07-11
BBB 30 2021-07-11 *Need this peak
BBB 20 2021-07-11
BBB 10 2021-07-11
CCC 10 2021-07-11
CCC 20 2021-07-11
CCC 30 2021-07-11
CCC 20 2021-07-11
CCC 10 2021-07-11
CCC 20 2021-07-11
CCC 30 2021-07-11
CCC 40 2021-07-11 *This peak won't count because the downtrend happens the next day
CCC 30 2021-07-12
CCC 20 2021-07-12
CCC 10 2021-07-12

The results for given day 2021-07-11 should be:

| Type | Total |
| ---- | ------ |
| AAA | 55 |
| BBB | 30 |
(CCC not included since there was no downtrend for the given date)

I'm not even really sure where to start except for maybe getting the value of each row that has a following row that is less (starts downtrending).

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,646 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MartinJaffer-MSFT 26,236 Reputation points
    2021-07-14T06:09:02.737+00:00

    If the data is always ordered like shown,

    do_compare( array , index )
      if (array[index].type == array[index-1].type) && (array[index].type == array[index+1].type)
        if (array[index].date == array[index-1].date) && (array[index].date == array[index+1].date)
          if (array[index].value > array[index-1].value) && (array[index].value > array[index+1].value)
            then increment_peak_tuple_dict( array[index].type, array[index].date, array[index].value )
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.