Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
mark2073
Frequent Visitor

Result from last 8 consecutive data points

mark2073_0-1731441605857.pngmark2073_1-1731441662761.png

Line chart and table for illustration

My example metric ( I have 16 in total to replicate ) where I'm trying to determine if the result of the last 8 consecutive data points are either under the trending regression line ( result = -8 ) or last 8 consecutive data points are above the regression line and therefore 8. If there is a +1, 0 or -1 in the last 8 that disrupts an output of -8 / +8, then a Measure wont trigger an up arrow (+8 ) or down arrow ( -8 )
I have a DateTable starting from 08/01/2023 ( 8th Jan 2023 ) to current date and is updated weekly so 96 Sundays so far
I have a Volume measure extracting from a Main Data table and a Regression measure, utilising the Volume measure and DateTable

 to determine the trend slope

I've created an additional measure to get a visual of Vol and Reg and Result

I've tried many different functions but can't seem to come up with a method to fetch the last 8 consecutive data points and sum to get either -8 in this case or +8
The Regression line needs to anchor back to 08/01/2023 to keep the slope as is but TOPN ( 8 ) seems to always adjust to last 8 LastDayOfWeek no matter what I do

I'd rather no have to go down the Power Query route and have to build all this in, and other remaining metrics that need 

2 REPLIES 2
Anonymous
Not applicable

Hi @mark2073 ,
You can try the following measures

IsAboveRegression = IF([Vol] > [Reg], 1, -1)
Last8Sum = 
VAR Last8Dates = 
    CALCULATETABLE(
        TOPN(8, DateTable, DateTable[LastDayOfWeek], DESC),
        ALL(DateTable)
    )
RETURN
    SUMX(
        FILTER(
            DateTable,
            DateTable[LastDayOfWeek]IN SELECTCOLUMNS(Last8Dates, "Date", DateTable[LastDayOfWeek])
        ),
        [IsAboveRegression]
    )
TriggerArrow = 
IF(
    [Last8Sum] = 8, 
    "Up Arrow", 
    IF(
        [Last8Sum] = -8, 
        "Down Arrow", 
        "No Arrow"
    )
)

Final output

vheqmsft_0-1731462139711.png

Best regards,
Albert He


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

Hi v-heq-msft, thanks for your reply. Unfortunately it's still not quite there and wondering if I need to change an element(s) within the model as I'm not getting the "expected" result. Something is skewing somewhere behind the scenes and I can't break it down enough to find out where. I recreated your 3 x Measures and used the results below ( Volumes can still increase over time as Users complete their ongoing information )

mark2073_0-1731960805085.png

Place the Measure in a Card and I get -2 and not -8. From what I originally created in DAX, I was getting the same unexpected result. Plugged a question into ChatGPT, gave me similar DAX but still incorrect result. Yours was similar DAX and still getting something unexpected. I may have to try a new method

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.