Skip to main content
Announcements
See why Qlik was named a Leader in the 2024 Gartner® Magic Quadrant™ for Data Integration Tools for the ninth year in a row: Get the report
cancel
Showing results for 
Search instead for 
Did you mean: 
ASC-Mike
Contributor II
Contributor II

RangeAvg(Above not working in a line chart

Hello Qlik Community,

I can't seem to get the RangeAvg(Above working in a line chart, it is reporting lower numbers than expected and what is reported in a straight table.  No problem using the RangeAvg(Above in a straight table.

The variable vMeasureSelector3 is made up of numerous master measures, one example is "OFD" which is this expression: Num(Count(if(StopTypeCode='D', StopNum)), '#,##0')

Here is the expression:

IF(
vAggregationType = 'Daily',
[$(vMeasureSelector3)],
IF(
vAggregationType = 'Rolling Average - 7',
RangeAvg(
Above([$(vMeasureSelector3)], 0, 7)
)
)
)

 

Thanks/Mike

Labels (1)
1 Solution

Accepted Solutions
Kushal_Chawda

@ASC-Mike  try below expression

IF(
    vAggregationType = 'Daily',
    [$(vMeasureSelection)], 
    IF(
        vAggregationType = 'Rolling Average - 7',
       sum(aggr(RangeAvg(Above([$(vMeasureSelection)], 0, 7)),[$(vDimensionSelection)],(Date,(NUMERIC))))
    )
)

 

View solution in original post

6 Replies
rubenmarin

Hi, maybe adding a TOTAL:

IF(
vAggregationType = 'Daily',
[$(vMeasureSelector3)],
IF(
vAggregationType = 'Rolling Average - 7',
RangeAvg(
Above(TOTAL [$(vMeasureSelector3)], 0, 7)
)
)
)

If doesn't works, you can upload a sample app (with some dummy data in an inline table) that demonstrates the issue so we can take a look.

ASC-Mike
Contributor II
Contributor II
Author

Hello @rubenmarin 

I stripped down the entire app and left just what is needed, using the same data that is in the SQL tables for the OFD (Stops).  App is attached.

This is what it should look like for the rolling 7, the first was output using python from the same data, the second is from a tableau app with same data.  The first line should all be in the mid to upper 200s.

Thanks/Mike

 

ASCMike_8-1728242609260.png


ASCMike_6-1728242312591.png

 

 

 

 

 

 

rubenmarin

Hi, the runnign average could be esasily calculated usiong the expression modifers, as:

rubenmarin_0-1728299223015.png

But I see there are days without data, should this days without data to be counted as 0 or just skipped from the average?

Note that when you use Above(...7) it will get the previous 7 values, which may not be the last 7 days as if there are skipped days, the last 7 values will go beyond those 7 days.

Having that in mind I would try to get the precalculated accumulated values in script, also the number of values used in that accumulation or a fixed '7' if skipped dates should count as zero.

Then the expression will be only the division between the accumulated and the number of days used for that date accumulation. this has many advantages, like performance ansd also you don't needd a chart with at least 7 valus to get the rolling avg, you can pick any date or arange of date and you will get the polling avg from the first point of data.

If there are many selections to by applied and the rolling avg should use them, maybe the solution is to use a similar scenario to an asofcalendar (https://community.qlik.com/t5/Design/The-As-Of-Table/ba-p/1466130) so each date can access the last 7 days data, allowing them to be calculated on execution time, without the need of precalculated accumulations.

Kushal_Chawda

@ASC-Mike  try below expression

IF(
    vAggregationType = 'Daily',
    [$(vMeasureSelection)], 
    IF(
        vAggregationType = 'Rolling Average - 7',
       sum(aggr(RangeAvg(Above([$(vMeasureSelection)], 0, 7)),[$(vDimensionSelection)],(Date,(NUMERIC))))
    )
)

 
ASC-Mike
Contributor II
Contributor II
Author

@Kushal_Chawda  Thanks that worked.  I similar variations using sum and aggr but clearly not as your solution.  Thanks again.

Kushal_Chawda

@ASC-Mike  Sorting date within Aggr is the key here.