Forum Discussion
Data from Measure for Last Trading Day
I've had a look again. I really can't see any difference. I've noticed you've added some test measures in both the datetable and the fact table; but I can't see their influence upon our final created measures.
hmmm
Oh they may be ones I was just messing around with. I created a calculated column in your Date table to help filter (index) faster,
And two calculated columns that show the close price for Today and Last Trading Date end with II
Probably need to add back in the filter for company name. I'd suggest merging this table to the main table for performance reasons.
- Phil_Seamark8 years agoMicrosoft EmployeeWill have a look in the morning
- ElliotP8 years agoPost ProdigyHow would I add the filter for the company name back to the closingpricedaybeforeII measure?
I'm still curious about a time intelligence function or if its worth creating tables and then just working off that? Since the tables would be worked on when the model is created it might solve the performance issue and let us use time intelligence functions. - ElliotP8 years agoPost Prodigy
Feelings anyone?
I'm curious if we are able to create the ClosingPriceDayBefore measure using time intelligence functions?
I'm not sure why at the moment I'm unable to use the ClosingPrice measure as the expression in a calculate function, hmmm
- Phil_Seamark8 years agoMicrosoft Employee
HI ElliotP
The main reason we can't simply subtract a day to the ClosingPrice measure is that the point in time for the previous trading day might be at a different part of the day. We still have to write DAX to establish what the maximum point in time is for the previous trading day and we have that.
- ElliotP8 years agoPost Prodigy
Phil_SeamarkThanks for the response.
If that would make life easier, we can to be honest. I would be happy to eat that inconsistency as it honestly never happens in this dataset. The dataset always ends at 4pm every single trading day except perhaps once per year.
I have scoured both pbix's and I honestly can't find the difference between the two. Both have the same relationships, data types; so I'm completly lost as to what the issue is.
Closing Price II = CALCULATE( MAX('StockBarData'[close]), LASTNONBLANK(StockBarData[LocalDateTime],1), FILTER(ALL('EquityReferenceTable'[CompanyName]),'EquityReferenceTable'[CompanyName]=MAX('EquityReferenceTable'[CompanyName])), 'DateTable'[TradingDay]="1" )I feel I understand out closing price measure. We filter the fact table to find the LASTNONBLANK datetime. We then filter the related Reference table as to find only the company we are looking. We finally have a condition where the Datetable must be a trading day.
Closing Price Day Before II = VAR x = MAX('DateTable'[Trading Day Index]) VAR y = MAXX(FILTER(ALL('StockBarData'),RELATED('DateTable'[Trading Day Index]) = x - 1),'StockBarData'[LocalDateTime]) RETURN MAXX(FILTER(ALL('StockBarData'[close],'StockBarData'[LocalDateTime]),'StockBarData'[LocalDateTime] = y),'StockBarData'[close])In our ClosingPriceDayBeforeII measure we are creating variable x which returns the maximum trading day index. We then create a variable which is maximum datetime resultant from creating a table that removes the filter context upon the fact table and then -1's from the from Trading Day Index whole number column. We then find the close after creating a table with all of the filter context's removed from the columns Close & the date time column where our datetime column equals our x variable.
I'm wondering how we could incorporate the CompanyNameReferencetable, would we just add the column to the ALL clause and set it to a newly created variable finding the MAX company name?
I have tried playing around with the formula's but I'm just not sure. When I do the below it does not seem to respect the filter for TradingDay:
ClosingPriceDayBefore = CALCULATE([Closing Price II], DATEADD(DateTable[DateKey], -1, DAY), DateTable[TradingDay] = "1" ) - ElliotP8 years agoPost Prodigy
I've added a new pbix file which pulls directly from the sql table; it is the same file as my working file.
Link: https://1drv.ms/u/s!At8Q-ZbRnAj8iGW8_wTuj5HnlsJj
It seems to be struggling with the dates; not sure.
- ElliotP8 years agoPost Prodigy
Feelings?