Forum Discussion
jonbox
3 years agoHelper II
Add a new column for a random sample
Hi, I'm looking to randomly select 50% of rows in a table based on a filter, creating a new column that adds "Sampled" to the row being sampled" I've tried the following code but it doesn't w...
- 3 years ago
I'm not sure if I understood you correctly, but try this anyway
Ahmedx
3 years agoSuper User
I'm not sure if I understood you correctly, but try this anyway
jonbox
3 years agoHelper II
Hi Ahmed, Thanks for the response.
I've got as far as the return expression but as soon as i put that in it says unexpected expression return.
Do you know why this might be?
Sampled =
VAR _select = "Low Value"
VAR _tbl = FILTER(ALL('hardcat HardcatAssets1'),'hardcat HardcatAssets1'[High Value Asset 2]=_select)
VAR _randomlyselect = COUNTROWS(_tbl) * 0.1 -- 10%
VAR _SampleSize = SELECTCOLUMNS( SAMPLE(_randomlyselect,_tbl,[Asset Code],ASC,"@Asset Code",[Asset Code],"@High Value Asset 2",[High Value Asset 2])
RETURN
IF(COUNTROWS(FILTER(_SampleSize,[@Asset Code]=[Asset Code]&&[@High Value Asset 2]=[High Value Asset 2])),"Sampled")
//SAMPLE(COUNTBLANK('hardcat HardcatAssets1'[Blank Value]) / 10 , 'hardcat HardcatAssets1', 'hardcat HardcatAssets1'[RFID Tag],ASC)
Thanks