The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi,
First post here. This should be simple for an experienced DAX person, and I'd greatly appreciate a suggestion or two. I have a table with weekly stock closing prices for a few thousand tickers. I want to calc the 40-week moving average for each ticker on each week, then count the number of tickers trading below their moving average for each week. Simple, but I can't get the last part...the count.
Here is the MA calc, which works perfectly:
Hi @elandry9840
how does your report look like? Can you share a screenshot of your data model?
Hi @elandry9840 ,
Not sure, is the first measure wrong?
Please use this measure and test.
40-week MA =
CALCULATE (
AVERAGE ( PriceTable[closeadj] ),
FILTER (
'Calendar',
'Calendar'[Date] <= MAX ( 'Calendar'[Date] )
&& 'Calendar'[Date]
>= MAX ( 'Calendar'[Date] ) - 200
)
)
Attached PBIX file for reference.
Best Regards,
Gao
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems with it, please feel free to let us know. Thanks a lot!
Hi v-cgao-msft,
Appreciate the reply!! I'm not sure it's working tho. Take a look:
Could it have something to do with the price table having data only once per week? I noticed your price table had dailt prices.
Thanks again!
Sure thing! Thanks for the reply!!
Not sure if this will be big enough. If not, let me know.
The screenshot is very small. However please try
Number of Stocks < 200Day MA =
VAR FortyWeekMA = [40-week MA]
RETURN
COUNTROWS ( FILTER ( 'PriceTable', PriceTable[closeadj] < FortyWeekMA ) )
Yes. Thank you, but doesn't seem to work. Must be something in my model that is peculiar.
Sorry. Here it is:
Would you please add the moving average measure and snother measure: COUNTROWS ( 'PriceTable')
Thank you so much for the help! I have to step out for an hour, but will be back after that and will reply promptly to whatever you need.
I apologize as well. It was too late and I fell asleep.
Are you sure you have a relationship. The results are not filtered at all. There is something wrong here
Thanks. I went back and deleted them then recreated them. Still no luck.
If possible, can you share a sample file?
Sure. How do I do that?
You can upload for example to We Transfer, DropBox or OneDrive and share the link
Please use the variable name inside FILTER same as the code I have shared
Replied to above
This is better:
Best:
User | Count |
---|---|
28 | |
11 | |
8 | |
6 | |
5 |
User | Count |
---|---|
35 | |
14 | |
12 | |
9 | |
7 |