Forum Discussion

CupidC's avatar
CupidC
Icon for Helper II rankHelper II
3 years ago
Solved

Extract a single column from a Filter table on the fly

Hi everyone,

 

I need some help with optimizing my code for extracting a column from a filtered table on the fly. Currently, my code works, but I have a feeling that there might be a more straightforward way to achieve this. I would appreciate any suggestions or improvements you may have.

 

Scenario:
I have a table containing customer information, and I want to extract the customer keys for customers with the fruit "Apple."

 

 

The code I wrote is as follows, and it is currently functional:

 

CusKEY Apple =
VAR CustomerAPPLE = FILTER('Customer','Customer'[Fruit]="Apple")
VAR ExtractKey = SELECTCOLUMNS(CustomerAPPLE,"KEY",[Customer Key])
Return
ExtractKey
 
Result


The above code provides the desired outcome of extracting the customer keys for those with "Apple" as the fruit.

 

If you have any ideas on how to make this code more efficient or any alternative approaches, please let me know.

Thank you all for your help and suggestions in advance!

 

Cupid

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi CupidC 

    IYou can create a measure

    Measure = IF(SELECTEDVALUE('Customer Key'[Fruit])="Apple",1,0)

    Then you can use a table visual , put the key column to the visual, then put the measure to the visual filter

     

    Output

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

     

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi CupidC 

    IYou can create a measure

    Measure = IF(SELECTEDVALUE('Customer Key'[Fruit])="Apple",1,0)

    Then you can use a table visual , put the key column to the visual, then put the measure to the visual filter

     

    Output

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.