Subscribe Bookmark RSS Feed

User chooses rows to subset?

hacketkm

Community Trekker

Joined:

Sep 14, 2012

Hello,

I would like to allow the user to select which rows to subset based on the values in one of the columns. They need to be able to select more than one value. I'm having trouble with selecting the rows based on which values the user chooses. :Generic Description is made up of character values, not numbers.

The code I am working with looks like this:

Summarize( GD = By( Column( dt, "Generic Description")));

nw = New Window( "Choose the Generic Descriptions to analyze",

     hb = HList Box(

          Panel Box( "Select the GDs",

          select1 = List Box(

               GD))

     ),

     Button Box( "OK",

          nw << Close Window;

          dt << Select Where( :Generic Description == select1 << Get Selected);

          dt << Subset(( Selected Rows), Output Table Name( "Selected GDs")))

);

Can anyone help me out?

1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The problem is that the results from "Get Selected" are a list.  You can't use the == operator in this context.  You can use contains to get the desired result:

dt = Current Data Table();

Summarize( GD = By( Column( dt, "Generic Description" ) ) );

nw = New Window( "Choose the Generic Descriptions to analyze",

    hb = H List Box(

        Panel Box( "Select the GDs",

            select1 = List Box( GD )

        )

    ),

    Button Box( "OK",

        select_list = select1 << Get Selected;

        dt << Select Where( contains(select_list, :Generic Description ));

        dt << Subset( (Selected Rows), Output Table Name( "Selected GDs" ) );

        nw << Close Window;

    );

);

2 REPLIES
Solution

The problem is that the results from "Get Selected" are a list.  You can't use the == operator in this context.  You can use contains to get the desired result:

dt = Current Data Table();

Summarize( GD = By( Column( dt, "Generic Description" ) ) );

nw = New Window( "Choose the Generic Descriptions to analyze",

    hb = H List Box(

        Panel Box( "Select the GDs",

            select1 = List Box( GD )

        )

    ),

    Button Box( "OK",

        select_list = select1 << Get Selected;

        dt << Select Where( contains(select_list, :Generic Description ));

        dt << Subset( (Selected Rows), Output Table Name( "Selected GDs" ) );

        nw << Close Window;

    );

);

hacketkm

Community Trekker

Joined:

Sep 14, 2012

Thank you very much! This works.