Excel根据组合总值在表格中对单元格进行分组

时间:2017-08-30 17:58:55

标签: excel

我想要一个客户名称列表,它们在一起的总和为1000.所以,如果jim和tod的总金额< = 1000和jim,tod,jill> = 1000然后列出jim和tod在一个单元格中,然后在下一个单元格中,如果jill,joy和pat< = 1000并且jill,joy,pat和tam> = 1000然后列出jill,joy和pat等等,直到所有客户端在列表中。 image of table

这可能吗?我正在学习,不知道从哪里开始,所以如果有人可以帮我指出正确的方向来解决这个问题,我将不胜感激?

1 个答案:

答案 0 :(得分:1)

Assuming your criterion for a group is that the money sums to less than or equal to 1000, then this is straightforward. Simply accumulate the Money amount down the list of names and start a new group and (reset the accumulator) whenever the cumulative amount exceeds 1000.

This gives you the group number for each name (see column apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26" defaultConfig { applicationId "com.notnow.barapp" minSdkVersion 19 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support:design:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' compile 'com.google.firebase:firebase-auth:10.0.1' compile 'com.facebook.android:facebook-android-sdk:[4,5)' compile 'com.android.support:support-v4:26.+' testCompile 'junit:junit:4.12' } apply plugin: 'com.google.gms.google-services' in picture below). A separate problem is then to list the names for each group number. In the picture, I have allowed for a maximum of 5 names per group but if real data indicates this is insufficient then allowing more is straightforward.

enter image description here

The set of groups obtained using this approach is dependent on the ordering of the rows of input data - change this ordering and the result is a different set of groups.

Perhaps a more interesting and challenging problem is to define a set of groups which meet not only the <=1000 criterion but also other criteria such as: minimise number of groups overall and equalise, as far as possible, the total money allocated to each group. But that is a very different problem!