Forum Discussion

dp32's avatar
dp32
Helper I
5 years ago
Solved

Expression.Error: We cannot apply field access to the type Number.

I am trying to randomize data in-place:

 

#"Randomize" = Table.TransformColumns(#"Changed Type1", {{"Value", each Number.RandomBetween(0.95,1.05)*[Value]}})

 

However, I get the following error message:

Expression.Error: We cannot apply field access to the type Number.
Details:
Value=4567,35
Key=Value

The column [Value] is of type number, so I don't understand the problem here.
Any idea? Thanks in advance.

  • Anonymous's avatar
    Anonymous
    5 years ago

    try this

    #"Randomize" = Table.TransformColumns(#"Changed Type1", {{"Value", each Number.RandomBetween(0.95,1.05)*_}})

     

     

    PS

    if the answer works for you and you want to know how and why it works, just ask

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    try this

    #"Randomize" = Table.TransformColumns(#"Changed Type1", {{"Value", each Number.RandomBetween(0.95,1.05)*_}})

     

     

    PS

    if the answer works for you and you want to know how and why it works, just ask

  • edhans's avatar
    edhans
    Community Champion

    It isn't in the current context. Try the following syntax:

     

            Table.TransformColumns(
                RowData, 
                {
                    {
                        "Value", 
                        each _ * Number.RandomBetween(0.95,1.05),
                        type number
                        }
                    }
                )

     

    However, note that this isn't doing what you think. Put this in a new custom column:

    Number.RandomBetween(0.5,.95)

    Every value is the same random number. You can either try the method in this article, or do what I would do. Either use a Measure in DAX, or a calculated column in DAX where each row or iteration is really random.

    MS should document this in their  Number.Random* documentation, but they don't. I just avoid both Number.Random and Number.RandomBetween in Power Query. DAX is better here, usually.

    • dp32's avatar
      dp32
      Helper I

      Thank you all. Working fine with the underscore.

      edhans , the random function is also working fine if I add an index column.

      • edhans's avatar
        edhans
        Community Champion

        Good to hear dp32 , glad you have a solution that works.