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 want a good spread over Rating, Classification, Class and Business area in the data set below. 

 

e.g. data

Customer NameRatingClassificationClassBusiness AreaValue
A10GoodFailUK156000
B15WatchGoodUSA157
C12GoodSubUK850000
D14StressedGoodUK984500
E12StressedGoodUK178130
F12GoodFailUSA648491
G12WatchSubEU1658403
H10GoodSubUK97
I10StressedGoodUK1654846546
J10WatchFailUSA548
K15StressedGoodEU2126654
L19GoodFailUK21687
M19StressedGoodUK1576
N18GoodSubUSA5654698
O12StressedGoodUK3216768
P15WatchGoodUK351648
Q19GoodFailUK115849

 

Thanks 

 

  • 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! 

     

3 Replies

  • v-janeyg-msft's avatar
    v-janeyg-msft
    Community Support

    Hi, D_HL 

     

    Do you want to randomly generate rate from the data in the next four columns?

    There is no such method in powerbi, you need to define a complete rule yourself according to the classification.

     

    Best Regards,
    Community Support Team _ Janey

  • D_HL's avatar
    D_HL
    Frequent Visitor

    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! 

     

    • v-janeyg-msft's avatar
      v-janeyg-msft
      Community Support

      Hi, D_HL 

       

      Glad you found a solution.🤗

      Okay, If your problem has been solved, you can mark your answer as solution to close the thread. 

       

      Best Regards,
      Community Support Team _ Janey