Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Dax Technical Analysis for trading (RSI, STOCH RSI, EMA, MA, ...)



I'm currently working on a report to analyze a few technical trading indicators. The major ones are RSI, stoch RSI, EMA and MA.


The table looks like this:


Symbol | TimeStamp | TimeFrame | Open | Close | Low | High | Volume From | Volume To


TimeStamp: date and time

TimeFrame: I could have deducted this with a measure but this would create more load, so decided to use SQL & powerquery to make seperate rows for timeframes 1h, 3h, 6h, 12h, 1d, 1w, 1m (all based on 1h).

... all others are self explanatory I guess.


I would like to start with the RSI (of last 14 records). Currenty I have the change between open & close:

Open: OpenX = OpenX = FIRSTNONBLANK(CoinData[Open],1)

Close: CloseX = CloseX = LASTNONBLANK(CoinData[Close],1)

Change: ChangeX = CALCULATE([CloseX]-[OpenX])

GainX = CALCULATE(if([ChangeX] >= 0 , [ChangeX],BLANK()))

LossX = CALCULATE(if([ChangeX] <= 0 , [ChangeX],BLANK()))


=> Based on the above, how do I get the averagex of the last 14 gainx records (including the current). Preferrably fixed per timeframe.

Frequent Visitor

I am looking to do the same thing as well, did you ever make any progress on this? 

Also, how did you approach bringing your data in and storing it?   Did you use SQL or did you do it through API or other services?

Personally I pulled my data in through API, 300 different tickers and I Have their entire history (daily).   Takes about 2 min to refresh (always open to faster options)

I set up a webservice in Azure to pull data on an hourly basis from multiple exchanges (APIs) into Azure SQL.



How difficult was it to set up the webservice?  I dont have any experience doing that


I was able to get a pretty solid database by generating .CSVs into folders.   I have 2 types of folders, Historical and Current.   The historical data loads 1x a day in the morning and current updates every 5 seconds.


The whole database takes about 2-3 minutes to generate.


From there I developed an SSIS package which loads the data into SQL staging, then from Staging I have stored procedures and jobs that complete a few calculations and clean the data.


Historical data loads 1x a day into production (Incremental load)

Current data loads every 15 minutes during market hours.  (flash and fill technique)


My goal is to get the current data in a PUSH API environment (hence me asking about the webservice).   I would IDEALLY like to get the current data to load into a Power BI dashboard -- as close to "live" as possible.  Then I would create drill downs for each ticker (I have 500 of them) and I can drill into each ticker and get the historical analysis for each ticker on demand.  


I also plan on running some Python or R along with this historical data so I can generate a rating system.  

Please let me know what you did with the webservice, maybe we can bat some ideas off each other, sounds like we are in the same game here.


"Historical performance is not indicative of future results"

No... but it is much much better than guessing!  🙂 



Hi @wlknsn,


Based on current information, I am not clear about what you were trying to achieve. Please follow this blog to provide more detailed information, such as sample dataset, desired output.



Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Let's say I'm looking for a calculation as in the table below in the last column. So per timeframe, I want the average of the previous 3 [close] values. The sorting is always by the [Date] field.


01/01/2018 00:00Hour4 
01/01/2018 01:00Hour4,5 
01/01/2018 02:00Hour75,166666667
01/01/2018 03:00Hour86,5
01/01/2018 04:00Hour98
01/01/2018 05:00Hour109
01/01/2018 06:00Hour1110
01/01/2018 00:00Day4 
01/02/2018 00:00Day12 
01/03/2018 00:00Day2012
01/04/2018 00:00Day2820
01/05/2018 00:00Day3628
01/06/2018 00:00Day4436
01/07/2018 00:00Day5244

I assume a filter combining:




TOPN(3,table,table[timestamp],desc) and EARLIER.

So the average of the last 3 records (current and previous two) based on timestamp for each timeframe. But how to combine these?

Forget the previous post:


AverageLast3recordsClose = calculate(average(close),allexcept(table, table[timeframe]]
That gives the average per timeframe, but now this has to be limited to the current and last 2 records (sorted by timeframe).


Appreciate your help!


This is what I have so far, but still one question remaining in terms of RSI (PS: the formula below covers pretty much everything from the subject line when you tweak this.


1) you need to create a calculated rank column (not measure), which will rank every record grouped by "Exchange", "Symbol" & "Interval".

Rank = 
ALLEXCEPT ( AllCandleData, AllCandleData[Exchange], AllCandleData[Symbol], AllCandleData[Interval] )

2) Based on this rank, you can now start to calculate the RSI over for example 14-records.

RSI = 

	GainCalc = abs(CALCULATE (
    AVERAGEx(AllCandleData, [Gain]),
    filter(ALLEXCEPT ( AllCandleData,AllCandleData[Symbol],AllCandleData[Exchange] ),
    AllCandleData[Rank] > (MAX(AllCandleData[Rank]) - 14 )
        && AllCandleData[Rank] <= MAX(AllCandleData[Rank])
	LossCalc = abs(CALCULATE (
    filter(ALLEXCEPT ( AllCandleData,AllCandleData[Symbol],AllCandleData[Exchange] ),
    AllCandleData[Rank] > (MAX(AllCandleData[Rank]) - 14 )
        && AllCandleData[Rank] <= MAX(AllCandleData[Rank])


if(LossCalc=0 , 100 , 100-(100/(1+DIVIDE(

This results in a table like this:


Now for my final question: what needs to be changed in the current RSI formula so I get the rsi per interval (fixed). So Seperate measures. As if you would apply (FILTER(ALL(table[Interval]), table[Interval] = 3h). Unfortunately, I don't seem to be able to add this in combination with the ALLEXCEPT. The result should be similar to be below (each column is seperate measure).


The result should be that on whatever timestamp I see in the column, I would have all the various RSI-interval values shown side by side as in the above.

PS: the RSI formula is rather CPU consuming. If you have any recommendations for optimizing this ... always welcome!

Looking to do these types of calculations under the same conditions. Any further progress to report?

Helpful resources

Winner of T-Shirt Design

Power BI T-Shirt Design Challenge 2023

Find out who won the T-Shirt Design Challenge and the top 3 finalists.

March 2023 Update3

Power BI March 2023 Update

Find out more about the March 2023 update.