Forum Discussion
Creating Batches
- 4 years ago
define column // First, create manually this column in your table... 'Statistics'[Helper] = rand() column 'Statistics'[Index] = // Then this one... var currentHelper = 'Statistics'[Helper] var Index = COUNTROWS( filter( 'Statistics', 'Statistics'[Helper] <= currentHelper ) ) return Index column Statistics[BatchId] = // Then this is going to be the one you need. // Hide the other two. Adjust the Batch BatchCount // variable. var RowCount = COUNTROWS( Statistics ) var BatchCount = 5 var Length = int( RowCount / BatchCount ) var BatchId = QUOTIENT( Statistics[Index], Length ) return BatchId // TESTING... EVALUATE 'Statistics' order by Statistics[BatchId]The above is test code that works in DAX Studio with any table you want (mine was called Statistics). All you have to do is to create the 3 columns (in the order of appearance) in your table. The sad thing is that if you want to do such things in DAX in the most general way, you have to use the random numbers...
Anonymous
OK... I understand you're not worried about which rows will get which batch number? What kind of columns do you have in the table? Is there one that is unique?
Yes you are right i just need to divide the entire table into batches. currently i have 856 rows, so will need to put them in 5 batches. Unfortunately i do not have columns that have unique values
- daXtreme4 years agoSolution Sage
define column // First, create manually this column in your table... 'Statistics'[Helper] = rand() column 'Statistics'[Index] = // Then this one... var currentHelper = 'Statistics'[Helper] var Index = COUNTROWS( filter( 'Statistics', 'Statistics'[Helper] <= currentHelper ) ) return Index column Statistics[BatchId] = // Then this is going to be the one you need. // Hide the other two. Adjust the Batch BatchCount // variable. var RowCount = COUNTROWS( Statistics ) var BatchCount = 5 var Length = int( RowCount / BatchCount ) var BatchId = QUOTIENT( Statistics[Index], Length ) return BatchId // TESTING... EVALUATE 'Statistics' order by Statistics[BatchId]The above is test code that works in DAX Studio with any table you want (mine was called Statistics). All you have to do is to create the 3 columns (in the order of appearance) in your table. The sad thing is that if you want to do such things in DAX in the most general way, you have to use the random numbers...
- Anonymous4 years agoNot applicable
This is nice! just some few clarification:
1 the first column basically creates a unique value for each row right?
2. what if i already have a unique column but is it is not a number, how will i be able to cummulatively count the rows?
3. If i already have a define length, let's say 200 i can already proceed withar BatchId = QUOTIENT( Statistics[Index], Length )
to assign value of length to 200 right?
- daXtreme4 years agoSolution Sage
Anonymous
1. Yes. But it's possible with rand(), even though highly improbable, that you could get 2 same values. But that should not matter much...
2. If you have a unique column and its values are comparable (even strings are), then you can use it instead of the one with rand(). The logic is exactly the same.
3. Yes, instead of defining how many batches you want, you can directly specify how long a batch
should be. Then, you don't have to calculate the length of the batch and the formula above is correct.