Forum Discussion

anwarbi's avatar
anwarbi
Helper III
4 years ago
Solved

Filtering a column based on a value from another column

Hi,

 

I am trying to filter my dataset based on certain conditions, consider the below example.

 

Lets say the below Table 1 is my dataset. what i am trying to do is:

If in the 'Company' column the value is ABZ then these name which appears against ABZ (Steve, Mike, Rad, Miller, Ricky) , should form my new dataset. (refer the next table below for expected output).  

 

Table 1

CompanyNameDept.HoursTopic
ABZSteveElectrical8Thesis
F&FBakerElectrical10Thesis
M&MSteveElectrical5Thesis
HVKMikeElectrical10Thesis
LamaNathanMechanical9Research
ABZMikeMechanical3Research
F&FCollinMechanical4Research
M&MBainAuto9Incubation
HVKIvyAuto5Incubation
LamaClairAuto2Incubation
ABZRadAuto9Incubation
F&FHashimRobotics6Thesis
M&MFafRobotics2Thesis
HVKRadRobotics2Thesis
LamaDevilliersCS10Thesis
ABZMillerCS6Research
F&FShaneCS4Research
M&MSteveCS8Research
HVKMathewChemical6Incubation
LamaRadChemical1Incubation
ABZRickyChemical8Incubation
F&FFahimChemical10Incubation
M&MMikeElectronic4Research
HVKGraceElectronic1Research

 

Table 2 (Expected Output / Filtered Data)

CompanyNameDept.HoursTopic
ABZSteveElectrical8Thesis
M&MSteveElectrical5Thesis
HVKMikeElectrical10Thesis
ABZMikeMechanical3Research
ABZRadAuto9Incubation
HVKRadRobotics2Thesis
ABZMillerCS6Research
M&MSteveCS8Research
LamaRadChemical1Incubation
ABZRickyChemical8Incubation
M&MMikeElectronic4Research

 

You would notice that in the expected filtered data in Table 2, the common names which were there for ABZ have been filtered from Table 1.

 

I am not sure, if this would require me to create a new column or a simple measure can be used to do this filtering. However, any help is highly appreciated.

 

Thanks 

  • Haha, what a fun requirement. Here's my take:

    Create a disconnected lookup table containing the company names. This will be used to populate the variable _Company in the measure, without filering our data.

    The _Company variabl collects all companies, that a specific worker is related to.

    The result checks, if the selected Company from the Disconnected Lookup is present in the _Companies variable 

     


    EDIT: 
    A few more arrows for clarification:

     

4 Replies

  • Haha, what a fun requirement. Here's my take:

    Create a disconnected lookup table containing the company names. This will be used to populate the variable _Company in the measure, without filering our data.

    The _Company variabl collects all companies, that a specific worker is related to.

    The result checks, if the selected Company from the Disconnected Lookup is present in the _Companies variable 

     


    EDIT: 
    A few more arrows for clarification:

     

    • NickolajJessen's avatar
      NickolajJessen
      Solution Sage

      Hi anwarbi,

      I received this in my mailbox, but can't see the comment here.

      Hi,

       

      Thanks for your help.

       

      While I am sure, this solution would work. I was curious, if we can add filter to the output table, just to select certain Companies.

       

      So for e.g.  in the current output, as per your table in power bi, we have ABZ, HVK, Lama and M&M as companies. From this table, would it be possible to select just HVK and M&M, by maybe adding a slicer?

       

      Thanks. Really appreciate.


       


      I I think adding the company field from the 'Table' would do the trick and filter the output.
      So you would have both Companny from the 'table' and the 'disconnectedtable'. Not very elegant, but it might be neccesarry for your specifik requirement.

      Appreciate your kudos 😊

      • anwarbi's avatar
        anwarbi
        Helper III

        Hi,

         

        yes, I realised that having two company field in the report would allow me to filter. I can't thank you enough, it was super helpful. ğŸ˜Š 

         

        Thanks

    • anwarbi's avatar
      anwarbi
      Helper III

      Hi NickolajJessen 

       

      This solution does work on 'Table' visual but when I use 'Bar chart' visual to calculate lets say Average hours and count of names, then despite having the measure filter of 1 applied on the visual, it still calculates the total count of names.

       

      I have attached the sample power bi file, basically I am looking to include the same data in Bar chart as in the table, e.g. In table there are 3 distinct count of names so I want to see the same count in Bar chart as well. 

       

      Thanks,