Forum Discussion
babajat
3 years agoFrequent Visitor
LOOKUPVALUE if date difference is smaller than two years
Good morning, I need help with a problem that has been bugging me for days. These are my data: ID DATE A DATE D I1 I2 I3 AA 30/01/2017 01/02/2017 FFF ZZZ BB 24/11/2021 24/11...
- 3 years ago
Hi , babajat
According to your description, you want to create two calculated columns from your logic. Right?
Here are the steps you can refer to :
(1)This is my test data:(2)We can click "New Column" and enter this:
Q1 = var _cur_ID = [ID] var _cur_DATE_A = [DATE A] var _cur_DATE_D = [DATE D] var _pre_dateA =MAXX( FILTER( 'Table' , 'Table'[ID] =_cur_ID && 'Table'[DATE A] < _cur_DATE_A) , [DATE A]) var _days = IF(_pre_dateA <> BLANK() , INT(_cur_DATE_D-_pre_dateA)) return IF(_days <= 730 && _days<> BLANK(), 1, 0)Q1 = var _cur_ID = [ID] var _cur_DATE_A = [DATE A] var _cur_DATE_D = [DATE D] var _pre_dateA =MAXX( FILTER( 'Table' , 'Table'[ID] =_cur_ID && 'Table'[DATE A] < _cur_DATE_A) , [DATE A]) var _days = IF(_pre_dateA <> BLANK() , INT(_cur_DATE_D-_pre_dateA)) return IF(_days <= 730 && _days<> BLANK(), 1, 0)(3)Then we can meet your need , the result is as follows:
Thank you for your time and sharing, and thank you for your support and understanding of PowerBI!
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Ashish_Mathur
Super User
3 years agoHi,
These calculated column formulas work
Column = if(CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[DATE d]>=EARLIER(Data[DATE A])-730&&Data[DATE D]<=EARLIER(Data[DATE A])))>1,1,BLANK())Column 2 = if(Data[Column]=1,CALCULATE(COUNTROWS(Data),FILTER(Data,Data[ID]=EARLIER(Data[ID])&&Data[DATE d]>=EARLIER(Data[DATE A])-730&&Data[DATE D]<EARLIER(Data[DATE A])&&(Data[I1]="XYZ"||Data[I1]="UUU"||Data[I2]="XYZ"||Data[I2]="UUU"||Data[I3]="XYZ"||Data[I3]="UUU"))),BLANK())
Hope this helps.