If all Values contain Text based on another range, then flag as TRUE

fdiddy

New Member
Joined
Nov 20, 2012
Messages
43
Hi All,
Stuck on the below in Power Query for Excel

Want to create a new column, if all values in Sold/Unsold equals "Unsold" for the particular product(in this case water slide), then Flag as 1

In this example below it should be false because all values are not "Unsold"

CountryproductSold/Unsold
Belgiumwater slideUnsold
Denmarkwater slideUnsold
Indiawater slideSold
Finlandwater slideSold
Netherlandswater slideSold
Norwaywater slideUnsold
Swedenwater slideSold

Desired Outcome
CountryproductSold/Unsold
Belgiumwater slideUnsold
0​
Denmarkwater slideUnsold
0​
Indiawater slideSold
0​
Finlandwater slideSold
0​
Netherlandswater slideSold
0​
Norwaywater slideUnsold
0​
Swedenwater slideSold
0​
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
1687429278654.png

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"product", type text}, {"Sold/Unsold", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Check", each if [#"Sold/Unsold"] = "Unsold" then 1 else 0),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Final", each if(List.Sum(#"Added Custom"[Check]))>0 then 1 else 0)
in
    #"Added Custom1"


You can reverse the 0 / 1 if needed
 
Upvote 0
Yes because you have different products, try this may not be the neatest but should work

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Country", type text}, {"product", type text}, {"Sold/Unsold", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Check", each if [#"Sold/Unsold"] = "Unsold" then 1 else 0),
    #"Grouped Rows" = Table.Group(#"Added Custom", {"product"}, {{"Final2", each List.Sum([Check]), type number}, {"Count2", each Table.RowCount(Table.Distinct(_)), Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"product"}, Table1, {"product"}, "Table1", JoinKind.LeftOuter),
    #"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"Country", "product", "Sold/Unsold", "Check"}, {"Table1.Country", "Table1.product", "Table1.Sold/Unsold", "Table1.Check"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Table1", "Final", each if([Final2]=[Count2]) then 0 else 1),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"product", "Final2", "Count2"})
in
    #"Removed Columns"
 
Upvote 0
If all are Unsold then 1 otherwise 0.
Perhaps the following:

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"product"}, {{"Count", each _}}),
    Sold = Table.AddColumn(Group, "UnSold", each if List.Contains([Count][#"Sold/Unsold"], "Sold", Comparer.Ordinal) then 0 else 1),
    Result = Table.ExpandTableColumn(Table.NestedJoin(Source, "product", Sold, "product", "Unsold"), "Unsold", {"UnSold"})
in
    Result
 
Upvote 0
Perfect smozger was just looking at tidying it up and explaining about the group option , thanks for stepping in ;) saved me .....
 
Upvote 0

Forum statistics

Threads
1,223,948
Messages
6,175,573
Members
452,652
Latest member
eduedu

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