+ Reply to Thread
Results 1 to 5 of 5

Power Query non volatile random list

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    777

    Power Query non volatile random list

    Hello,
    is there a way to create a random list in Power Query; that will not recalculate;
    so this works, but is volatile,

    Please Login or Register  to view this content.
    In xl id use
    Please Login or Register  to view this content.
    then just copy past values in place.

    i have asked this on fabric, but had no solution, there may not be one?

    Please Login or Register  to view this content.
    Richard.

  2. #2
    Registered User
    Join Date
    02-29-2024
    Location
    EGYPT - Cairo
    MS-Off Ver
    MS365
    Posts
    99

    Re: Power Query non volatile random list

    Your requirement really leads me to learn a new thing, so thanks to you first of all.

    To generate a list of numbers that looks random but remain the same non volatile when you refresh your query, I found a technique that I was not aware about it, which may achieve the fixed random sequences in power query after refresh in all cases.

    It is called a Linear Congruential Generator (LCG), of course it is not a native built-in in power query but i mean to apply it in power query context.

    The idea is simple:
    1. Start with a Fixed Number.
    2. Multiply by a Fixed Factor
    3. Add a Fixed Increment
    4. Divide and Keep the Remainder
    5. That Remainder Is the Next Fixed Number
    6. Repeat the Process

    We used 4 factors to apply this technique:
    • seed or starting point, which is #1
    • multiplier, which is #2
    • increment, (they used to call it modulus), and this one affect the randon numbers which is #3
    • modulus, which is #4.

    Other items we used of numbers you want in the list are :
    lowerBound: lower or beginner
    upperBound: maximum or end

    So, now we have 4 fixed numbers or items:
    seed or starting point: This is the starting value and is not directly shown in the final list.
    multiplier: 1103515245, they are recommending to use this value for it and many opinions says it is a proven value, but honestly i was not able to figure out why this one in particular.
    increment: this is any random number you pick, but you need to fix it.
    modulus: after doing the multiplication and addition, you divide by the modulus and keep the remainder.

    So we follow this:
    Starting with the Seed
    Use the function to generating the First Number
    Building the Sequence
    Removing the Original Seed

    Now lets move to power query part:
    I created a table in excel to include all parameters as follow:
    Notes are not my words, but I copied it from the paper I've explored to learn the concept, so I thought to copy it in full so you can understand it better.
    Excel 2016 (Windows) 64 bit
    A
    B
    C
    D
    1
    Linear Congruential Generator
    2
    Factor Vaue Note
    3
    Seed
    123,456,789
    Fixed This is your fixed starting value. The LCG algorithm uses this value to begin the sequence generation. It isn’t directly part of the final output but determines the entire sequence.
    4
    Multiplier
    1,103,515,245
    Fixed This number is multiplied by the current value at each step. Its proven effectiveness (and widespread use) ensures that when combined with the other parameters, the generated numbers have good distribution.
    5
    Increment
    12,345
    Fixed After multiplying by the multiplier, this fixed number is added to help prevent the sequence from becoming too regular or cyclic too quickly.
    6
    Modulus
    2,147,483,648
    Fixed After multiplying and adding, the result is divided by the modulus and the remainder is kept. This operation confines the computed values within a specific range (0 to Modulus – 1). The value 2,147,483,648 is 2³¹, a common choice for many LCG implementations.
    7
    Lower Bound
    9
    Change To Fit Your Needs These parameters allow you to scale the raw output of the LCG into a more useful range.
    8
    Upper Bound
    250
    Change To Fit Your Needs These parameters allow you to scale the raw output of the LCG into a more useful range.
    9
    List Count
    20
    Change To Fit Your Needs This determines how many numbers (or iterations) the generator should produce. You can change this value if you need more or fewer numbers in your output list.
    Sheet: Sheet1

    Then I load it to the power query to LCG, and pivot column value.

    Then referenced it to a new query Params. and converted this to a record, so I can use it else where as needed.

    Then added a new blank query, and then adjust parameters and formula.

    Here are the code with more explain for your references.

    This is the code for the LCGSequence:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Here are the end result:
    Excel 2016 (Windows) 64 bit
    A
    11
    Here is the list
    12
    LCGSequence
    13
    35
    14
    156
    15
    192
    16
    248
    17
    96
    18
    59
    19
    191
    20
    111
    21
    112
    22
    174
    23
    85
    24
    96
    25
    65
    26
    247
    27
    86
    28
    188
    29
    138
    30
    17
    31
    43
    32
    101
    Sheet: Sheet1
    Last edited by MohamedGadAllah; 04-14-2025 at 06:34 AM.
    Thank,
    Mohamed GadAllah

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    777

    Re: Power Query non volatile random list

    Thank you Mohammed,
    i have not had a chance to go through this, but it looks very interesting, I shall have a read up on
    LCG ,
    I've had not other replies.
    I'll accept this, and I'll let you know how I get on.

    Richard.

  4. #4
    Registered User
    Join Date
    02-29-2024
    Location
    EGYPT - Cairo
    MS-Off Ver
    MS365
    Posts
    99

    Re: Power Query non volatile random list

    Thanks for your reply, and I hope this may help.

  5. #5
    Registered User
    Join Date
    02-29-2024
    Location
    EGYPT - Cairo
    MS-Off Ver
    MS365
    Posts
    99

    Re: Power Query non volatile random list

    Thanks for the reputation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Power Query List.Select list of values
    By Dicken in forum Office 365
    Replies: 3
    Last Post: 06-10-2024, 03:13 AM
  2. Replies: 1
    Last Post: 07-14-2023, 10:15 AM
  3. [SOLVED] Power query convert list of list to list of tables
    By Dicken in forum Office 365
    Replies: 3
    Last Post: 06-13-2023, 03:16 PM
  4. [SOLVED] Power query M transform list of list to text
    By Dicken in forum Office 365
    Replies: 6
    Last Post: 04-03-2023, 09:44 AM
  5. Replies: 8
    Last Post: 10-21-2020, 03:02 AM
  6. Replies: 7
    Last Post: 10-05-2020, 12:29 PM
  7. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1