Forum Discussion

babajat's avatar
babajat
Frequent Visitor
3 years ago
Solved

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...
  • v-yueyunzh-msft's avatar
    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