Forum Discussion

Omelei's avatar
Omelei
Frequent Visitor
3 years ago
Solved

Create new column with previous ID

Hi 

 

I've created the following table. 

 

Account IDOpp IDPrevious Opp IDStartdateRevenueCustom Previous Opportunity ID
100000006AAA006AAB1-1-2023 € 250.000 
100000006AAB006AAC1-10-2022 € 220.000 
100000006AAC 1-1-2022 € 200.000 
100001006ABA006ABB3-1-2023 € 1.000.000 
100001006ABB 1-1-2023 € 1.500.000006ABC
100001006ABC 1-1-2022 € 1.000.000006ABD
100001006ABD 1-1-2021 € 800.000 

 

 

In the Happy flow the previous opportunity id is automatically filled. However, in some cases it is not. If the previous opportunity ID is not known, I'd like to define it by searching for the Opportunity ID of the Account with the most recent Agreement start date. 

 

Please take into account the oldest opportunity of the account should not contain a previous opportunity id.

 

Hope you can help. 

  • hi Omelei 

     

    try to add the column with this:

    Custom Previous Opportunity ID 2 = 
    VAR _id = [Account ID]
    VAR _date = [Startdate]
    VAR _table =
    FILTER(
        data,
        data[Account ID] = _id
    )
    VAR _date1=
    MAXX(
        FILTER(
            _table,
             data[Startdate]<_date
        ),
        data[Startdate]
    )
    RETURN
    MAXX(
        FILTER(
           _table,
            data[Startdate] = _date1
        ),
        data[Opp ID]
    )

     

    it shall work like this:

3 Replies

  • Omelei , Create a new column like

     

    Var Max = maxx(filter(Table, Table[Account ID] = earlier([Account ID]) && [Start Date] < earlier([Start Date]) ) ,[Start Date])

    return

    maxx(filter(Table, Table[Account ID] = earlier([Account ID]) && [Start Date] =_max ) ,[Opp ID])

     

    Power BI DAX- Earlier, I should have known Earlier: https://youtu.be/CVW6YwvHHi8

  • hi Omelei 

     

    try to add the column with this:

    Custom Previous Opportunity ID 2 = 
    VAR _id = [Account ID]
    VAR _date = [Startdate]
    VAR _table =
    FILTER(
        data,
        data[Account ID] = _id
    )
    VAR _date1=
    MAXX(
        FILTER(
            _table,
             data[Startdate]<_date
        ),
        data[Startdate]
    )
    RETURN
    MAXX(
        FILTER(
           _table,
            data[Startdate] = _date1
        ),
        data[Opp ID]
    )

     

    it shall work like this: