Forum Discussion
Anonymous
6 years agoNot applicable
Excel Formula to PowerBI formula
Hello I would like to transform these last 4 coulmn formulas to PowerBI formulas
Maturity ID OBS_DATE Price Calculated_Closing_Date Contract_Date_Befor Price_Before_Date Contract_Date_After Price_After_Date
| 01M | 300071513 | 10/11/2019 | 54.76 | 11/11/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/10/2019 | 53.56 | 11/10/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/9/2019 | 52.60 | 11/9/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/8/2019 | 52.62 | 11/8/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/7/2019 | 52.73 | 11/7/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/4/2019 | 52.78 | 11/4/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/3/2019 | 52.41 | 11/3/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61 |
| 01M | 300071513 | 10/2/2019 | 52.58 | 11/2/2019 | 10/22/2019 | 52.59 | 11/20/2019 | 52.61
|
Table3:
Expiration_Date Settle
| 10/22/2019 | 52.59 |
| 11/20/2019 | 52.61 |
| 12/19/2019 | 52.48 |
| 1/21/2020 | 52.29 |
| 2/20/2020 | 52.12 |
| 3/20/2020 | 51.92 |
| 4/21/2020 | 51.72 |
| 5/19/2020 | 51.5 |
| 6/22/2020 | 51.27 |
| 7/21/2020 | 51.04 |
| 8/20/2020 | 50.85 |
| 9/22/2020 | 50.7 |
| 10/20/2020 | 50.6 |
| 11/20/2020 | 50.52 |
| 12/21/2020 | 50.41 |
| 1/20/2021 | 50.32 |
What I have in Excel:
Contract_Date_Before =IF([@[Calculated Closing Date]]<MIN(Table3[Expiration_Date]),NA(),MAX((Table3[Expiration_Date]<[@[Calculated Closing Date]])*Table3[Expiration_Date])) Price_Before_Date =INDEX(Table3[Settle],MATCH([@[Contract_Date_Before]],Table3[Expiration_Date],0))
Contract_Date_After =MIN(IF(Table3[Expiration_Date]>[@[Calculated Closing Date]],Table3[Expiration_Date])) Price_After_Date =INDEX(Table3[Settle],MATCH([@[Contract_Date_After]],Table3[Expiration_Date],0))
Explanation:
I calculate a contract closing date, then from a list of existing contracts [Table3] i take the closest one before the calculated closing date and the one with the closest date after the calculated closing date, with their respective prices
(note that, if the calculated closing date has a perfect match, just take that, so maybe an IFFERROR(index-match, formula) can work
I apprecciate any help,
wish you all the best,
Luca.
Hi Anonymous ,
You could use the following DAX queries:
Contract_Date_Before = IF ( 'Table'[Calculated_Closing_Date] < MIN ( Table3[Expiration_Date] ), BLANK (), MAXX ( FILTER ( Table3, Table3[Expiration_Date] < 'Table'[Calculated_Closing_Date] ), Table3[Expiration_Date] ) )Price_Before_Date = LOOKUPVALUE ( Table3[Settle], Table3[Expiration_Date], 'Table'[Contract_Date_Before] )Contract_Date_After = MINX ( FILTER ( Table3, Table3[Expiration_Date] > 'Table'[Calculated_Closing_Date] ), Table3[Expiration_Date] )Price_After_Date = LOOKUPVALUE ( Table3[Settle], Table3[Expiration_Date], 'Table'[Contract_Date_After] )
1 Reply
- v-eachen-msft
Community Support
Hi Anonymous ,
You could use the following DAX queries:
Contract_Date_Before = IF ( 'Table'[Calculated_Closing_Date] < MIN ( Table3[Expiration_Date] ), BLANK (), MAXX ( FILTER ( Table3, Table3[Expiration_Date] < 'Table'[Calculated_Closing_Date] ), Table3[Expiration_Date] ) )Price_Before_Date = LOOKUPVALUE ( Table3[Settle], Table3[Expiration_Date], 'Table'[Contract_Date_Before] )Contract_Date_After = MINX ( FILTER ( Table3, Table3[Expiration_Date] > 'Table'[Calculated_Closing_Date] ), Table3[Expiration_Date] )Price_After_Date = LOOKUPVALUE ( Table3[Settle], Table3[Expiration_Date], 'Table'[Contract_Date_After] )