Forum Discussion
LOOKUPVALUE if date difference is smaller than two years
- 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
Hi! Thanks for the answer. I'm afraid that your measure is returning 1 if the difference is grater than 730 days instead of smaller. If i swap the ">730" with "<730" it stops working correctly for some reason (it seems that it stops filtering by ID) 😵
Furthermore, using this measure returns "1" on both the most recent and oldest entries, is there a way to highlight only the most recent?