Test if Source Table is empty

AllisterB

Board Regular
Joined
Feb 22, 2019
Messages
120
Office Version
  1. 365
Platform
  1. Windows
Hi
I am trying to test if the Source table is empty before I do the transformations.

My attempt does work I get an error "Expression.Error: The import Changed Type matches no exports. Did you miss a module reference?"

The error has only occurred since I inserted the If then else piece of code.

What do I need to change ?

Thank You

Allister

Power Query:
let


    Source = Excel.CurrentWorkbook(){[Name="t_AccredoBranches"]}[Content],
    #"Test If t_AccredoBranches Empty" = if Table.IsEmpty(t_AccredoBranches) then "All values are null" else
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"Column2", type any}, {"Column3", type any}}),
    #"Removed Top Rows" = Table.Skip(#"Changed Type",5),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Code", type text}, {"Name", type text}, {"Inactive", type text}}),
    #"Uppercased Text" = Table.TransformColumns(#"Changed Type1",{{"Inactive", Text.Upper, type text}}),
    #"Added Custom" = Table.AddColumn(#"Uppercased Text", "Custom", each Text.PadStart(Text.From([Code]),4,"0")),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Code"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Name", "Inactive"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Custom", "Branch Code"}}),
    #"Filtered Rows" = Table.SelectRows(#"Renamed Columns", each ([Inactive] = "FALSE")),
    #"Added Custom1" = Table.AddColumn(#"Filtered Rows", "Source", each "Existng Branch Codes"),
    #"Appended Query" = Table.Combine({#"Added Custom1", #"t_BranchTPKBranchCodes (2)"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Appended Query",{{"Branch Code", type text}, {"Inactive", type text}}),
    #"Added Conditional Column" = Table.AddColumn(#"Changed Type2", "Custom", each if [Source] = null then "New TPK  Branch Codes" else [Source]),
    #"Removed Columns1" = Table.RemoveColumns(#"Added Conditional Column",{"Source"}),
    #"Appended Query1" = Table.Combine({#"Removed Columns1", t_UserBranches}),
    #"Added Conditional Column1" = Table.AddColumn(#"Appended Query1", "Custom.1", each if [Custom] = null then "User Branches" else [Custom]),
    #"Renamed Columns1" = Table.RenameColumns(#"Added Conditional Column1",{{"Custom.1", "Source"}}),
    #"Capitalized Each Word" = Table.TransformColumns(#"Renamed Columns1",{{"Source", Text.Proper, type text}}),
    #"Sorted Rows1" = Table.Sort(#"Capitalized Each Word",{{"Source", Order.Ascending},{"Branch Code", Order.Ascending}}),
    #"Replaced Value" = Table.ReplaceValue(#"Sorted Rows1","Tpk","TPK",Replacer.ReplaceText,{"Source"}),
    #"Removed Columns2" = Table.RemoveColumns(#"Replaced Value",{"Custom"}),
    #"Filtered Rows1" = Table.SelectRows(#"Removed Columns2", each ([Branch Code] <> null))
in
    #"Filtered Rows1"
 
Last edited:

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.
I assume you found your own solution. Do you mind posting about your solution? Then it is perfectly fine to mark your post as the solution to help future readers.

If there is no solution, please do not mark a post as a solution that is not a solution.
 
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,113
Members
452,544
Latest member
aush

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