PowerPivot/PowerQuery: new Column and row context

SOQLee

Board Regular
Joined
Mar 18, 2015
Messages
58
Office Version
  1. 365
Platform
  1. Windows
Working in Excel 2013 PowerPivot and PowerQuery. In the first sample table below, the '0' needs to be replaced with the Account value in the previous row if the IDs are the same. Something similar to the Excel IF statement, ie. =IF(B2=B1,IF(C2=0,C1,C2),C2) using DAX or M. The second sample table is what I would like.

RowIDAccount
1A11111
2A0
3A22222
4A0
5B33333
6B0
7B0
8B0
9B0
10C44444
11C44444
12C44444
13C44444
14C44444
15C44444
16C44444
17C44444
18C0
19D55555
20D0
21D0
22E66666
23E66666
24E66666
25E66666
26E66666
27E77777
28F88888
29F0
30F0
31G0
32G99999
33G99999

<tbody>
</tbody>


This is what I would like to see:

RowIDAccount
1A11111
2A11111
3A22222
4A22222
5B33333
6B33333
7B33333
8B33333
9B33333
10C44444
11C44444
12C44444
13C44444
14C44444
15C44444
16C44444
17C44444
18C44444
19D55555
20D55555
21D55555
22E66666
23E66666
24E66666
25E66666
26E66666
27E77777
28F88888
29F88888
30F88888
31G0
32G99999
33G99999

<tbody>
</tbody>
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
In the Query editor right click the Account header and select Fill>Down.
 
Last edited:
Upvote 0
Unfortunately, that won't work for Rows 30, 31
 
Upvote 0
Actually, you'll need an extra step - you'll first have to replace the 0s with Null.

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Replaced Value" = Table.ReplaceValue(Source,0,null,Replacer.ReplaceValue,{"Account"}),
#"Filled Down" = Table.FillDown(#"Replaced Value",{"Account"})
in
#"Filled Down"


Here's the result.


Row ID Account
1 A 11111
2 A 11111
3 A 22222
4 A 22222
5 B 33333
6 B 33333
7 B 33333
8 B 33333
9 B 33333
10 C 44444
11 C 44444
12 C 44444
13 C 44444
14 C 44444
15 C 44444
16 C 44444
17 C 44444
18 C 44444
19 D 55555
20 D 55555
21 D 55555
22 E 66666
23 E 66666
24 E 66666
25 E 66666
26 E 66666
27 E 77777
28 F 88888
29 F 88888
30 F 88888
31 G 88888
32 G 99999
33 G 99999
 
Last edited:
Upvote 0
in Excel > place cursor on Table > menu Power Query > click on From Table > in Power Query Editor > on left side of window > right click on Table which is imported > click Duplicate > select duplicate table > remove column Row > select column Account > uncheck 0 > remove Duplicates > select column ID > remove Duplicates > click on Close & Load To > select Only Create Connection > click OK


menu Power Query > click Merge > select original table name and then select duplcated table name > select column ID for both tables > select Left Outer > click OK


you got the result but ID A having account 2222 will not appear. add some extra letter to A to get that also
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,849
Members
449,096
Latest member
Erald

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top