Forum Discussion

D_HL's avatar
D_HL
Frequent Visitor
4 years ago
Solved

Random Sample

Hi everyone,    Wondering if Power BI can select a random sample however with criteria. I have a data set and want a sample that has a good spread over 4 columns in the data.    For example I wan...
  • D_HL's avatar
    4 years ago

    Thanks for the response. I think I have solved with some Dax which creates a table for each column I want to randomise and forms a union of those tables. Its a long process but I think it will work. I just create a table per column for the sample spread? 

     

    Random Selection with category filter and sample size =

    VAR SampleSize = XX

    VAR Cat_Name1TableWithRand =

    TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name1"), "Rand", RAND () ), [Rand])

    VAR Cat_Name2TableWithRand =

    TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name2"), "Rand", RAND () ), [Rand])

    VAR Cat_Name3TableWithRand =

    TOPN (SampleSize, ADDCOLUMNS ( FILTER('Table_Name', 'Table_Name'[Column1] = "Cat_Name3"), "Rand", RAND () ), [Rand])

    VAR UnionTable =

    UNION (Cat_Name1TableWithRand , Cat_Name2TableWithRand , Cat_Name3TableWithRand )

     

    RETURN UnionTable

     

    If there is a quicker way, then great!