Forum Discussion
Select data according to certain date
Hi everyone,
I would ask for your support and knowledge to help me to solve this topic.
I have a set of prices, for few contracts, launched in some dates. I need to filter all the items which its Contract_Month and Contract_Year are above or equal to the latest date's month and year (30/10/2020).
As per example:
| Date | Contract_Month | Contract_Year | Price |
| 30/10/2020 | 01 | 2021 | 10 |
| 29/09/2020 | 09 | 2020 | 2,1 |
| 01/08/2020 | 01 | 2021 | 11 |
| 02/06/2020 | 08 | 2020 | 7 |
| 02/06/2020 | 12 | 2020 | 3 |
Desired output
| Date | Contract_Month | Contract_Year | Price |
| 30/10/2020 | 01 | 2021 | 10 |
| 01/08/2020 | 01 | 2021 | 11 |
| 02/06/2020 | 12 | 2020 | 3 |
Thanks in advance for any help you can give.
Regards,
10 Replies
- camargos88
Community Champion
Anonymous ,
You can create a measure like this:
_Filter = VAR _date = DATE(SELECTEDVALUE('Table'[Contract_Year]), SELECTEDVALUE('Table'[Contract_Month]), 1) RETURN IF(_date >= DATE(2020, 10,30), 1, 0)Use this measure to filter the visual.
- AnonymousNot applicable
Hi camargos88 ! Thanks for your answer. I think that may succeed, but the date should be the MAX in the Date column, instead of static. I know well, that October 30th is the latestet in the example, but the data model will be updated on a daily basis.
Cheers
- camargos88
Community Champion
Anonymous ,
You can replace this block with:
CALCULATE(MAX(TABLE[DT_DATE]), ALL(TABLE))
- camargos88
Community Champion
Anonymous ,
Dá uma olhada no arquivo anexado.
Criei uma fórmula para comparar as datas e filtrar o visual:
_Filtro = VAR _dateCotacao = SELECTEDVALUE('Table'[DATA_COTACAO]) VAR _dateContrato = DATE(SELECTEDVALUE('Table'[Ano_Contrato]), SELECTEDVALUE('Table'[Mês Contrato]), 1) RETURN IF(_dateContrato >= _dateCotacao, 1, 0)- AnonymousNot applicable
Olá camargos88 ! Vi o ficheiro que enviaste. Quando selecciono o filtro "0", obtenho 3 itens acima da ultima data do mercado. Da mesma forma se seleccionar o filtro "1", a query devolve 6 itens com mes/ano abaixo da ultima data do mercado.
- camargos88
Community Champion
Anonymous ,
No caso do filtro com 0, se comparar novembro de 2020 com março/abril de 2020 deveria retornar zero, não ?
No caso do filtro com 1, os anos são posteriores ao da data_cotacao, não ?
Talvez eu tenha entendido a necessidade errada, essa solução compara as datas em cada linha. Se for algo diferente disso, me explique novamente por favor.