Add column, fill with 3 random values only

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need to add a column to my table which contains values "Met", "Partially met" and "Not met" but I can't figure out how to do this.

I've tried to add a column and fill with RANDBETWEEN(1,3), but it returns a mixed number, but each row contains the same random value, e.g. 1.34567

Unable to find an answer online, can anyone suggest how to add the 3 values above as a new column in random order?

TIA,
Jack
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You need an Index column for RandomBetween to work correctly. Here is an example of what you are talking about doing.

Book3
ABCDE
1Column1Column1Value
2a,b,c,da,b,c,dNot Met
3e,f,g,he,f,g,hNot Met
4I,jkMet
5kI,jPartially Met
6llPartially Met
7mmMet
8n,o,p,zn,o,p,zMet
Sheet4


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    Type = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    AddedIndex = Table.AddIndexColumn(Type, "Index", 0, 1, Int64.Type),
    Random = Table.AddColumn(AddedIndex, "Custom", each Int64.From(Number.RandomBetween(1,3))),
    Lookup = Table.FromRecords({[Number=1,Value="Met"],[Number=2,Value="Partially Met"],[Number=3,Value="Not Met"]}),
    Merge = Table.NestedJoin(Random, {"Custom"},Lookup, {"Number"}, "Lookup", JoinKind.LeftOuter),
    Expand = Table.ExpandTableColumn(Merge, "Lookup", {"Value"}, {"Value"}),
    ROC = Table.SelectColumns(Expand,{"Column1","Value"})
in
    ROC
 
Upvote 0
Solution
Here is another way to do it without needing to add and remove an index column.

Book1
AB
1Column1Custom
2a,b,c,dMet
3e,f,g,hPartially Met
4I,jNot Met
5kPartially Met
6lPartially Met
7mMet
8n,o,p,zNot Met
Table5


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    RB = Table.AddColumn(Source, "Custom", each 
        let 
            input = Number.Round(Number.RandomBetween(1,3)),
            vals = List.Zip({{1,2,3},{"Met","Partially Met", "Not Met"}}),
            Result = List.First(List.Select(vals, each _{0}=input)){1}
        in
            Result
    )
in
    RB
 
Upvote 0

Forum statistics

Threads
1,223,721
Messages
6,174,091
Members
452,542
Latest member
Bricklin

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