Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

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:

DateContract_MonthContract_YearPrice
30/10/202001202110
29/09/20200920202,1
01/08/202001202111
02/06/20200820207
02/06/2020122020

3

Desired output

DateContract_MonthContract_YearPrice
30/10/202001202110
01/08/202001202111
02/06/2020122020

3

Thanks in advance for any help you can give.

Regards,

10 Replies

  • camargos88's avatar
    camargos88
    Icon for Community Champion rankCommunity 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.

    • Anonymous's avatar
      Anonymous
      Not 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's avatar
        camargos88
        Icon for Community Champion rankCommunity Champion

        Anonymous ,

         

        You can replace this block with:

         

        CALCULATE(MAX(TABLE[DT_DATE]), ALL(TABLE))

  • camargos88's avatar
    camargos88
    Icon for Community Champion rankCommunity 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)
    • Anonymous's avatar
      Anonymous
      Not 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's avatar
    camargos88
    Icon for Community Champion rankCommunity 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.