Forum Discussion
Create new column with previous ID
Hi
I've created the following table.
| Account ID | Opp ID | Previous Opp ID | Startdate | Revenue | Custom Previous Opportunity ID |
| 100000 | 006AAA | 006AAB | 1-1-2023 | € 250.000 | |
| 100000 | 006AAB | 006AAC | 1-10-2022 | € 220.000 | |
| 100000 | 006AAC | 1-1-2022 | € 200.000 | ||
| 100001 | 006ABA | 006ABB | 3-1-2023 | € 1.000.000 | |
| 100001 | 006ABB | 1-1-2023 | € 1.500.000 | 006ABC | |
| 100001 | 006ABC | 1-1-2022 | € 1.000.000 | 006ABD | |
| 100001 | 006ABD | 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
- amitchandakSuper User
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
- OmeleiFrequent Visitor
Thank you amitchandak
Unfortunately it throws a syntax error for RETURN. Any idea? - FreemanZSuper User
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: