Forum Discussion
Data from Measure for Last Trading Day
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"
)
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.
- Phil_Seamark8 years agoMicrosoft EmployeeWill have a look in the morning
- ElliotP8 years agoPost Prodigy
Feelings?