Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
michaelsh
Kudo Kingpin
Kudo Kingpin

FIFO Join in Power Query

My customers have services that can be activated and disactivated.

One customer can have several active services at the same time.

Activation and disactivation are Orders.

The disactivation order disactivates the earliest order of "activation" type (that hasn't been disactivated already) - FIFO.

I need to connect a disactivation date to all my "activation" orders.

Please see the sample.

Please help.

michaelsh_0-1621147183359.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @michaelsh 

OK, I think I make a mistake that keep 3333 which make disactivated happens before any Activation occurs.

Please try this way. Firstly, we need to add a Flag in Original Table to find Order Number happens before any Activation occurs like 3333.

Add an Index in Original Table. Then build three custom columns by M query.

Count Activated Before:

 

List.Count(
    Table.SelectRows(
        #"Added Index",
     (r) =>r[Order Type] = "Service Activated"
     and [Index] >= r[Index] )[Order Number]
     )

 

Count Order Per Type:

 

List.Count(
    Table.SelectRows(
        #"Added Custom",
         (r) =>[Order Type] = r[Order Type]
         and [Index] >= r[Index] )[Order Number]
         )

Flag:

if [Order Type] = "Service Disactivated" and [Count Per Order Type]>[Count Activated Before] then "Delete" else "OK"

New Table is as below.

1.png

Filter Flag column, only show "OK" value and then remove Index and three custom columns. We will get a table without 3333. Then repeat the operation in my previous reply.

2.png

You can download the pbix file from this link.

 

Best Regards,

Rico Zhou

 

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

 

 

View solution in original post

4 REPLIES 4
michaelsh
Kudo Kingpin
Kudo Kingpin

Geat, thanks a lot, @Anonymous 

I'll need to look into these List functions more...

Anonymous
Not applicable

Hi @michaelsh 

Try to transform your table and use Merge function in Power Query Editor.

I use your sample to have a test.

1.png

Firstly, pivot Order Type column as below.

3.png

Duplicate Orginal Data table and name it as Orginal Data (2). We will get active value in Orginal Data table, and get deactive value in Orginal Data (2). So we need to remove Service Disactivated in Orginal Data and remove Service Activated in Orginal Data (2).

Then remove null values in Service Activated and  Service Disactivated columns.

4.png

Add an Index column in two tables.

Then merge two tables by index column.

5.png

Expand Orginal Table 2 and reomve index column. Result is as below.

6.png

You can download the pbix file from this link.

 

Best Regards,

Rico Zhou

 

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

Thanks, @Anonymous 

The result is not exactly what I expect.

Please see the order 3333. It shouldn't disconnect anything, since it happens before any Activation occurs.

The order that should disconnect 4444 is 7777, not 3333

Thanks!

Anonymous
Not applicable

Hi @michaelsh 

OK, I think I make a mistake that keep 3333 which make disactivated happens before any Activation occurs.

Please try this way. Firstly, we need to add a Flag in Original Table to find Order Number happens before any Activation occurs like 3333.

Add an Index in Original Table. Then build three custom columns by M query.

Count Activated Before:

 

List.Count(
    Table.SelectRows(
        #"Added Index",
     (r) =>r[Order Type] = "Service Activated"
     and [Index] >= r[Index] )[Order Number]
     )

 

Count Order Per Type:

 

List.Count(
    Table.SelectRows(
        #"Added Custom",
         (r) =>[Order Type] = r[Order Type]
         and [Index] >= r[Index] )[Order Number]
         )

Flag:

if [Order Type] = "Service Disactivated" and [Count Per Order Type]>[Count Activated Before] then "Delete" else "OK"

New Table is as below.

1.png

Filter Flag column, only show "OK" value and then remove Index and three custom columns. We will get a table without 3333. Then repeat the operation in my previous reply.

2.png

You can download the pbix file from this link.

 

Best Regards,

Rico Zhou

 

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

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors