Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
nalingupta94
Frequent Visitor

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.

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

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"))

Ashish_Mathur_1-1715916005916.png

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

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"))

Ashish_Mathur_1-1715916005916.png

 

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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

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


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey @Ashish_Mathur, Please find the data attached:

Check year

Code

Date

Final Date

201911/01/201927/03/2019
201911/02/201927/03/2019
201913/03/201927/03/2019
2019127/03/201927/03/2019
2019127/05/201927/03/2019
201913/06/201927/03/2019
2019125/06/201927/03/2019
201921/07/201928/08/2019
2019225/07/201928/08/2019
201923/08/201928/08/2019
2019228/08/201928/08/2019
201929/09/201928/08/2019
2019211/09/201928/08/2019
2019212/12/201928/08/2019
202011/01/202026/03/2020
202011/02/202026/03/2020
202013/03/202026/03/2020
2020126/03/202026/03/2020
2020127/05/202026/03/2020
202013/06/202026/03/2020
2020125/06/202026/03/2020
202021/07/202025/08/2020
2020225/07/202025/08/2020
202023/08/202025/08/2020
2020225/08/202025/08/2020
202029/09/202025/08/2020
2020211/09/202025/08/2020
2020212/12/202025/08/2020
202111/01/202120/03/2021
202111/02/202120/03/2021
202113/03/202120/03/2021
2021120/03/202120/03/2021
2021127/05/202120/03/2021
202113/06/202120/03/2021
2021125/06/202120/03/2021
202121/07/202129/08/2021
2021225/07/202129/08/2021
202123/08/202129/08/2021
2021229/08/202129/08/2021
202129/09/202129/08/2021
2021211/09/202129/08/2021
2021212/12/202129/08/2021

 

Explanation: If the Code is 1, select the MAX date March, where 'check year' = final date[year].
If the code is 02 select the MAX date in August where 'check year' = final date[year].

Please let me know if youd like any additional information.

I do not understand.  Show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks so much @Ashish_Mathur.

Worked like a charm.

amitchandak
Super User
Super User

@nalingupta94 , A new column in dax

 

= if([code] =2 , date(Year([Date]), 8, day([Date]) ), [Date] )

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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.