Forum Discussion

selinozdemirpbi's avatar
selinozdemirpbi
New Member
3 years ago
Solved

Checking if value exist for 45 days

Hi,

 

I want to check that if a value exist for 45 daysbefore a spesific date. In this way i want to find that if that order is the first order after 45 days for every user.

 

Here is my example table. I want to create the check column.

customer idorder datecheck
110.10.2022no (first order)
112.10.2022yes (it's just 2 days)
112.02.2023yes (first order after 4 months)
201.09.2022no (first order)
230.10.2022yes (fisrt order after several days)
202.11.2022no

 

Thank you very much

  • Hi selinozdemirpbi ,

    According to your description, you want to get the first day more than 45 days away from the first order, here's my solution. Add a custom column in Power Query:

    let min=List.Min(Table.SelectRows(#"Changed Type",(x)=>x[customer id]=[customer id])[order date])  in if [order date]=List.Min(Table.SelectRows(#"Changed Type",each Duration.Days([order date]-min)>=45)[order date]) then "yes" else "no"

    Get the correct result:

    I attach my sample below for your reference.

     

    Best regards,

    Community Support Team_yanjiang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 Replies

  • Vijay_A_Verma's avatar
    Vijay_A_Verma
    Most Valuable Professional

    What is your logic for yes and no...Your last order for ID 1 is after 4 months but marked as yes. 

  •  

    Chk =
    VAR __interval =
        [order date]
            - CALCULATE( MIN( 'Order'[order date] ), ALLEXCEPT( 'Order', 'Order'[customer id] ) )
    RETURN
        SWITCH(
            TRUE(),
            __interval = 0, "First",
            __interval < 45, "Several days",
            "No"
        )

     

  • Hi selinozdemirpbi ,

    According to your description, you want to get the first day more than 45 days away from the first order, here's my solution. Add a custom column in Power Query:

    let min=List.Min(Table.SelectRows(#"Changed Type",(x)=>x[customer id]=[customer id])[order date])  in if [order date]=List.Min(Table.SelectRows(#"Changed Type",each Duration.Days([order date]-min)>=45)[order date]) then "yes" else "no"

    Get the correct result:

    I attach my sample below for your reference.

     

    Best regards,

    Community Support Team_yanjiang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.