Forum Discussion

bibbilibobbili's avatar
bibbilibobbili
Frequent Visitor
4 years ago

SMA trendlines issue

Good morning everyone.

 

Has anyone come across this problem in the past? My simple moving average trendlines seems to get confused and bleed into each other. I'm not sure how this is happening as the two measures for the trendlines are filtered separately.

I'm trying to have a graph where you can select two items from a slicer, and compare their trends next to each other on the same plot.

I'm using FIRSTNONBLANK and LASTNONBLANK to filter from the same table. When I have just one of these selected, the trendline behaves as expected. When two are selected the trendlines seems to interact with eachother, like some data is somehow getting past the filter.

 

Det01 1 Year MA =
var myvalue = FIRSTNONBLANK(Dets[Index2],Dets[Index2])
return
CALCULATE(AVERAGE('Table'[Result]),
FILTER(Dets[Index2],Dets[Index2] = myvalue),
DATESINPERIOD(CalendarTable[Date],LASTDATE(CalendarTable[Date]),-365, DAY))

 

Det02 1 Year MA =
var myvalue = LASTNONBLANK(Dets[Index2],Dets[Index2])
return
CALCULATE(AVERAGE('Table'[Result]),
FILTER(Dets[Index2],Dets[Index2] = myvalue),
DATESINPERIOD(CalendarTable[Date],LASTDATE(CalendarTable[Date]),-365, DAY))
 

Thanks for reading

2 Replies

  • I think what's happening is that when you have just one, it's not plotting the null value dates (where myvalue is blank) but when you have two, it can no longer simply ignore these dates.

  • v-xiaotang's avatar
    v-xiaotang
    Community Support

    Hi bibbilibobbili 

    Not sure which step is wrong, could you share a sample file for us to test?

    Besides, what's your expected result in detail? We will check your measure based on it.

     

    Best Regards,

    Community Support Team _Tang

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