Forum Discussion
Comparing open and close on different dates
- 4 years ago
In this case I would create a calculated table as your criteria are fixed and don't need to be affected by slicers.
Comparison Table = GENERATE( VALUES( 'Stock'[symbol]), var symbol = 'Stock'[Symbol] var openPrice = LOOKUPVALUE( 'Stock'[open], 'Stock'[Symbol], symbol, 'Stock'[Date], DATE(2014,1,2)) var closePrice = LOOKUPVALUE( 'Stock'[close], 'Stock'[Symbol], symbol, 'Stock'[Date], DATE(2017,11,29)) return ROW( "Open", openPrice, "Close", closePrice, "Diff", closePrice - openPrice) )You can then use this new table in visuals or in calculations
No this is a measure. Click on "New Measure" and paste the complete code including the name.
After that choose the matrix visual and drag the symbol column to the raws and the new measure to the values
Thanks, that is now working.
Though, another user provided a solution, which is providing different results;
Comparison Table = GENERATE( VALUES( 'Stock'[symbol]), var symbol = 'Stock'[Symbol] var openPrice = LOOKUPVALUE( 'Stock'[open], 'Stock'[Symbol], symbol, 'Stock'[Date], DATE(2014,1,2)) var closePrice = LOOKUPVALUE( 'Stock'[close], 'Stock'[Symbol], symbol, 'Stock'[Date], DATE(2017,11,29)) return ROW( "Open", openPrice, "Close", closePrice, "Diff", closePrice - openPrice) )
Do you have any idea as to why this would be the case?
- tamerj14 years agoCommunity Champion
It might be becuase you have multiple records in the same date. In this LOOKUPVALUE returns blank snd SUM aggregates the total value
- Anonymous4 years agoNot applicable
Thanks Tamerj.
Though to add to my confusion, I've just manually opened the data set and done the calculation for one of the stocks, and I've received a different value entirely than both of these solutions provide.
Going a bit numbers blind now, ha.