Forum Discussion

nalingupta94's avatar
nalingupta94
Frequent Visitor
2 years ago
Solved

Finding required date.

Hi all,

 

I am fairly new to powerBI, and am still trying to figure out a lot of it's functioning. I am working on generating a report, and one of the requirements is to replace a date. Below is a dummy dataset to provide more context.

In my fact table I have three columns (marked in blue) and based on these three columns, I want to calculate the new column (marked in red)

 

Checking yearCodeDate Updated date

2019

0119/01/2019 19/03/2019
20190119/03/2019 19/03/2019
20190219/08/2019 19/08/2019
20200130/03/2020 30/03/2020
20200210/08/2020 10/08/2020
20200211/11/2020 10/08/2020
20210112/05/2021 29/03/2021
20210129/03/2021 29/03/2021
20210222/08/2021 22/08/2021
20220130/3/2022 30/3/2022
20220219/08/2022 19/08/2022
2022028/12/2022 19/08/2022

 

The Logic:

From the above table, I want to check if code =01 AND checking year = YEAR(date), then select the date that has month =3.
If code =02 AND checking year = YEAR(date) then select the date with month = 8.


Would appreciate any help available. Also happy to provide further information, so please reach out!

Thanks in advance!

 

Nalin.

  • Hi

    This calculated column formula works

    Column = if(and(Data[Code]="1",Data[Checking year]=Data[Year]),LOOKUPVALUE(Data[Date],Data[Monnth number],CALCULATE(MIN(Data[Monnth number]),FILTER(Data,Data[Checking year]=EARLIER(Data[Year])&&Data[Code]="1"&&Data[Monnth number]=3)),Data[Checking year],Data[Year],Data[Code],"1"),LOOKUPVALUE(Data[Date],Data[Monnth number],8,Data[Checking year],Data[Year],Data[Code],"2"))

     

     

8 Replies

    • nalingupta94's avatar
      nalingupta94
      Frequent Visitor

      Hi amitchandak,

      this is pretty close, but I would like the day to be same as the day with month = 08.

      e.g. if the dates are 10/09/2022(date A)  & 20/08/2022 (date B).

      Date A should be replaced by date B.

  • Hi

    This calculated column formula works

    Column = if(and(Data[Code]="1",Data[Checking year]=Data[Year]),LOOKUPVALUE(Data[Date],Data[Monnth number],CALCULATE(MIN(Data[Monnth number]),FILTER(Data,Data[Checking year]=EARLIER(Data[Year])&&Data[Code]="1"&&Data[Monnth number]=3)),Data[Checking year],Data[Year],Data[Code],"1"),LOOKUPVALUE(Data[Date],Data[Monnth number],8,Data[Checking year],Data[Year],Data[Code],"2"))

     

     

    • nalingupta94's avatar
      nalingupta94
      Frequent Visitor

      Hi Ashish_Mathur , just out of curiosity, is there a way to manage lookupvalue, if it returns multiple dates with the selected month?

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Share data in a format that can be pasted in an MS Excel file and show the expected result with an explanation.