Forum Discussion
Distinct search for a value based on validity date
- 3 years ago
Hi, Harry1980
You can try the following methods.
Measure = Var _Selectyearmonth=YEAR(SELECTEDVALUE(BillingDate[Date]))*100+MONTH(SELECTEDVALUE(BillingDate[Date])) Var _Closedyearmonth=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])&&[Yearmonth]<=_Selectyearmonth),[Yearmonth]) Var _Colsedvalue=CALCULATE(MAX('Table'[Standard Price]),FILTER(ALL('Table'), [Yearmonth]=_Closedyearmonth&&[Material]=SELECTEDVALUE('Table'[Material])))+0 Var _Maxyearmonth=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])),[Yearmonth]) Var _Maxvalue=CALCULATE(MAX('Table'[Standard Price]),FILTER(ALL('Table'), [Yearmonth]=_Maxyearmonth&&[Material]=SELECTEDVALUE('Table'[Material])))+0 Return IF(_Selectyearmonth>=_Maxyearmonth,_Maxvalue,_Colsedvalue)Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, Harry1980
You can try the following methods.
Measure:
Yearmonth = SELECTEDVALUE('Table'[Year])*100+SELECTEDVALUE('Table'[Period])Measure =
Var _Selectyearmonth=YEAR(SELECTEDVALUE(BillingDate[Date]))*100+MONTH(SELECTEDVALUE(BillingDate[Date]))
Var _Closedyear=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])&&[Yearmonth]<=_Selectyearmonth),[Year])
Var _Closedmonth=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])&&[Yearmonth]<=_Selectyearmonth),[Period])
Return
CALCULATE(SUM('Table'[Standard Price]),FILTER(ALL('Table'),
[Year]=_Closedyear&&[Period]=_Closedmonth&&[Material]=SELECTEDVALUE('Table'[Material])))+0
Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Charlotte,
thank you for your reply. Your suggestion does not exactly match what I would like to achieve. I see now that I should have provided more info. I have created another way. It works fine as long as for the year a material was billed also a standard price record exists/was created. For example for materials A-D the last record were created in 2021. Then my formula finds correct standard price until billing date 31.12.2021. But from 01.01.2022 the result is blank even though the last records from 2021 should still be valid for 2022 and 2023. For example for Material A the record valid from 02 2021 is the last available record and hence this would be still valid in case something was billed in 2022 or 2023. In this case it would be 2 for material
A in 2022 and 2023
Is there any smart way making it work also for 2022 or 2023?
Thank you in advance
Harry
used expression:
Before I have derived the code below I have added a month and a year column and have also increased the date range in table billing date (from 01.01.2019-31.12.2023) in order to be able to verify whether my code works
| Material | Billing date | Standard Price |
| A | 31.01.2023 | 2 |
| B | 31.01.2023 | 3 |
| C | 31.01.2023 | 7 |
| D | 31.01.2023 | 9 |
| A | 31.01.2021 | 11 |
| B | 31.01.2021 | 4 |
| C | 31.01.2021 | 0 |
| D | 31.01.2021 | 6 |
| A | 31.10.2019 | 0 |
| B | 31.10.2019 | 0 |
| C | 31.10.2019 | 0 |
| D | 31.10.2019 | 6 |
- v-zhangti3 years agoCommunity Support
Hi, Harry1980
You can try the following methods.
Measure = Var _Selectyearmonth=YEAR(SELECTEDVALUE(BillingDate[Date]))*100+MONTH(SELECTEDVALUE(BillingDate[Date])) Var _Closedyearmonth=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])&&[Yearmonth]<=_Selectyearmonth),[Yearmonth]) Var _Colsedvalue=CALCULATE(MAX('Table'[Standard Price]),FILTER(ALL('Table'), [Yearmonth]=_Closedyearmonth&&[Material]=SELECTEDVALUE('Table'[Material])))+0 Var _Maxyearmonth=MAXX(FILTER(ALL('Table'),[Material]=SELECTEDVALUE('Table'[Material])),[Yearmonth]) Var _Maxvalue=CALCULATE(MAX('Table'[Standard Price]),FILTER(ALL('Table'), [Yearmonth]=_Maxyearmonth&&[Material]=SELECTEDVALUE('Table'[Material])))+0 Return IF(_Selectyearmonth>=_Maxyearmonth,_Maxvalue,_Colsedvalue)Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.