Power Query - Fill Down with conditions

weslake77

New Member
Joined
May 19, 2018
Messages
10
Hi all,
I have a profit and loss report that includes a Category column and a Sub Category column.
I filled down the Category column with great success. However, there only exists a handful of Sub Categories in a data set with hundreds of rows.
See pics below. The Sub Categories normally have a cell with the text that describes the Sub Category and then a couple of blanks rows, then the same Sub Category written with the addition of the word "Total". (See pics)
How do I Fill Down between these 2 values as a typical Fill Down will also repeat the "Total...." Sub Cat as well which isn't correct.
Any ideas??
 

Attachments

  • Fill Down 1.jpg
    Fill Down 1.jpg
    94.8 KB · Views: 102
  • Fill Down 2.png
    Fill Down 2.png
    26.3 KB · Views: 101

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
post a link to the shared (dropbox, onedrive or any similar) excel file with you problem
 
Upvote 0
I don't know what you want in the yellow section
result
Closing stock - cattle
Closing stock - cattle
Total Closing stock - cattle
Killed for rations - cattle
Killed for rations - cattle
Total Killed for rations - cattle
Opening stock - cattle
Opening stock - cattle
Total Opening stock - cattle
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
Total CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
 
Last edited:
Upvote 0
or like this
result
null
Closing stock - cattle
Closing stock - cattle
Total Closing stock - cattle
Killed for rations - cattle
Killed for rations - cattle
Total Killed for rations - cattle
Opening stock - cattle
Opening stock - cattle
Total Opening stock - cattle
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
Total CATTLE - Other
null
null
null
null
null
null
null
null
null
 
Upvote 0
or like this
result
null
Closing stock - cattle
Closing stock - cattle
Total Closing stock - cattle
Killed for rations - cattle
Killed for rations - cattle
Total Killed for rations - cattle
Opening stock - cattle
Opening stock - cattle
Total Opening stock - cattle
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
CATTLE - Other
Total CATTLE - Other
null
null
null
null
null
null
null
null
null
Yes that one is what I'm after. I didn't want to attach actual power query as it has a lot of sensitive info.
 
Upvote 0
try adapt this
note: it's tailored to your example only
Rich (BB code):
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    IF1 = Table.AddColumn(Source, "Custom", each if Text.Contains([Sub Category], "Total") then [Sub Category] else null),
    IF2 = Table.AddColumn(IF1, "Custom.1", each if not Text.Contains([Sub Category], "Total") then [Sub Category] else null),
    ReplaceErr = Table.ReplaceErrorValues(IF2, {{"Custom", null}, {"Custom.1", null}}),
    FillD = Table.FillDown(ReplaceErr,{"Custom.1"}),
    ReplaceNull = Table.ReplaceValue(FillD,null," ",Replacer.ReplaceValue,{"Custom", "Custom.1"}),
    IF3 = Table.AddColumn(ReplaceNull, "Custom.2", each if Text.Contains([Custom], "Total") then [Custom] else if [Index] > 87 then " " else [Custom.1]),
    ReplaceSpace = Table.ReplaceValue(IF3," ",null,Replacer.ReplaceValue,{"Custom.2"}),
    TSC = Table.SelectColumns(ReplaceSpace,{"Index", "Income or Expense", "Category", "Custom.2", "Date", "Type", "Num", "Description", "Amount"}),
    Ren = Table.RenameColumns(TSC,{{"Custom.2", "Sub Category"}}),
    Type = Table.TransformColumnTypes(Ren,{{"Index", Int64.Type}, {"Date", type date}, {"Amount", type number}})
in
    Type
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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