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! Learn more

Reply
CornelisV
Advocate II
Advocate II

Replace previous, current and next row with a blank in a column depending on score of other column

Dear all,

 

See here an example of a table:

ColumnAColumnBColumnC
30030
350 
451 
150 
13013
500

50

 

Column A should be transfered into column C, depending omn the score of column B. If the score of column B is 1, then the previous, current and next row of column A must be replaced by a blank with Column C as result. 

Any idea how to solve: DAX or Power M Query?

 

Best regards,

 

Cornelis

 

2 ACCEPTED SOLUTIONS
GeraldGEmerick
Solution Supplier
Solution Supplier

@CornelisV You would need an index column to define "previous" and "next". If you have an index column then you could do something like the following:

Column C = 
VAR _CurrentIndex = [Index]
VAR _ColumnA = [ColumnA]
VAR _ColumnB = [ColumnB]
VAR _PreviousColumnB = CALCULATE( SUM( [ColumnB] ), FILTER( 'Table', [Index] = _CurrentIndex - 1 ) )
VAR _NextColumnB = CALCULATE( SUM( [ColumnB] ), FILTER( 'Table', [Index] = _CurrentIndex + 1 ) )
VAR _Return = IF( _ColumnB + _PreviousColumnB + _NextColumnB > 0, BLANK(), _ColumnA )
RETURN _Return

View solution in original post

mickey64
Super User
Super User

For your reference.

 

Step 0: I use this data below.

mickey64_0-1761060338116.png

 

Step 1: I make 3 tables below in Power Query Editor.

<DATA_0>

mickey64_1-1761060503057.png

 

<DATA_+1>

mickey64_2-1761060529293.png

 

<DATA_-1>

 

mickey64_3-1761060559973.png

 

Step 2: I merge queries below.

mickey64_4-1761060626400.pngmickey64_5-1761060655864.png

mickey64_6-1761060720995.png

 

Step 3: I merge queries below too.

mickey64_7-1761060782812.pngmickey64_8-1761060809788.png

mickey64_9-1761060850536.png

 

Step 4: I replace 'null' to '0' and add a custum column below.

mickey64_11-1761061218873.png

 

Step 5: I chage type of ColumnC and delete 3 columns below.

<Before>

mickey64_12-1761061410565.png

 

<After>

mickey64_13-1761061438779.png

 

 

 

View solution in original post

4 REPLIES 4
CornelisV
Advocate II
Advocate II

Hi @GeraldGEmerick ,

 

Thank you for the solution, it works.

This is a smart and fast solution and works well if you want to apply 2 or more steps back or forward. For your information, the scores 0 and 1 in column B are the valves of a process equipment where 0 = close and 1 = open and we have > 100,000 observations.

 

Best regards,

 

Cornelis

mickey64
Super User
Super User

For your reference.

 

Step 0: I use this data below.

mickey64_0-1761060338116.png

 

Step 1: I make 3 tables below in Power Query Editor.

<DATA_0>

mickey64_1-1761060503057.png

 

<DATA_+1>

mickey64_2-1761060529293.png

 

<DATA_-1>

 

mickey64_3-1761060559973.png

 

Step 2: I merge queries below.

mickey64_4-1761060626400.pngmickey64_5-1761060655864.png

mickey64_6-1761060720995.png

 

Step 3: I merge queries below too.

mickey64_7-1761060782812.pngmickey64_8-1761060809788.png

mickey64_9-1761060850536.png

 

Step 4: I replace 'null' to '0' and add a custum column below.

mickey64_11-1761061218873.png

 

Step 5: I chage type of ColumnC and delete 3 columns below.

<Before>

mickey64_12-1761061410565.png

 

<After>

mickey64_13-1761061438779.png

 

 

 

Dear @mickey64 ,

 

Thank you for providing M Query solution, it works!

It is very interesting to see that the solution from @GeraldGEmerick and ythat from ou are very different, all going to the same result. The solution from @GeraldGEmerick requires DAX knowledge, whereas from you more in Power M query. Have a great day,

 

Cornelis

GeraldGEmerick
Solution Supplier
Solution Supplier

@CornelisV You would need an index column to define "previous" and "next". If you have an index column then you could do something like the following:

Column C = 
VAR _CurrentIndex = [Index]
VAR _ColumnA = [ColumnA]
VAR _ColumnB = [ColumnB]
VAR _PreviousColumnB = CALCULATE( SUM( [ColumnB] ), FILTER( 'Table', [Index] = _CurrentIndex - 1 ) )
VAR _NextColumnB = CALCULATE( SUM( [ColumnB] ), FILTER( 'Table', [Index] = _CurrentIndex + 1 ) )
VAR _Return = IF( _ColumnB + _PreviousColumnB + _NextColumnB > 0, BLANK(), _ColumnA )
RETURN _Return

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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