This seems to do the trick;  probably could be factorised better.
Performance might suffer for large A.  How big/complex is it?

cw   =: 2&}.   NB. get colourways
con  =: 1&{    NB. get consumption
u    =: ~.@(-.&0)  NB. nub excluding 0
ucw  =: [EMAIL PROTECTED]   NB. get nub of cw excluding 0

NB. stitch it all together
all  =: ;@:(<@|:@({. , ucw , (,~ +/)@(con * (u =/~ ])@cw))"1)
  
   B (-: all) A
1

Mike
  

Alex Rufon wrote:
> Hello.
>
> This has stumped me. I just cant get my brains around this one.
>  
> I have this table (TABLE A):
> TABLE A                                               
>
material_code   consumption     colorway1       colorway2       colorway3       
colorway4       colorwayN
> 10    0.5     15      25      35      45      0
> 20    0.2     15      35      0       0       0
> 30    1       15      0       45      0       0
> 40    0.8     15      45      0       45      0
>
> And I need to transform into this format (TABLE B):
> TABLE B                                                       
>
material_code   color   total   colorway1       colorway2       colorway3       
colorway4       colorwayN
> 10    15      0.5     0.5     0       0       0       0
> 10    25      0.5     0       0.5     0       0       0
> 10    35      0.5     0       0       0.5     0       0
> 10    45      0.5     0       0       0       0.5     0
> 20    15      0.2     0.2     0       0       0       0
> 20    35      0.2     0       0.2     0       0       0
> 30    15      1       1       0       0       0       0
> 30    45      1       0       0       1       0       0
> 40    15      0.8     0.8     0       0       0       0
> 40    45      1.6     0       0.8     0       0.8     0
>
> Please note that the number of colorways may be from 1 to N. Its
arbitrarily sized. 
>
> I've also attached a capture of the excel file on the event that this
becomes unreadable.
>
> I would really appreciate if anybody would give my problem a go.
Otherwise ... I'll do a brute-force solution. I have an idea on how to do
this but its going to be really ugly with a lot of branching and
conditions. Oh well, I'm going get some sleep (been away for 20 hours). 
>
> Thanks in advance to anybody who give this a go. I appreciate any help.
>
> Thanks again.
>
> r/Alex
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.476 / Virus Database: 269.10.8/904 - Release Date:
16/07/2007 17:42


--------------------------------------------------------------------
mail2web - Check your email from the web at
http://link.mail2web.com/mail2web


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to