This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
your solution works for this particular case; however, as the data will change, this solution will not work. so i guess i am looking for a solution that can sample different groups of record based on the percentage they weight in the total population.
Sum number of records, append that on. Then group by the ID and count. Then divide that count by the total. That gives you the percentage. Take that percentage and join back on by ID. Then create a batch macro and the Batch would be the ID, and the value for the batch is the percentage. That percentage is then used in the sampling tool to dictate how many records to take. The batch macro will then union the outputs and away you go.
What you're trying to do is a random sample based on a grouping. I often have this need and created the attached macro a long time ago. It's basically just spin on the already existing macro "Random % Sample".
Save this to your Alteryx Macro location, which is most likely "C:\Program Files\Alteryx\bin\RuntimeData\Macros". The new macro "RandomRecords_Grouped" will then show on the Preparation palate of your Designer.
For your example, you'd select a random 50% of your records, and check the "User ID" field for the "Select random records for each value to the following field(s):" portion of the configuration.