Forum Discussion

RichOB's avatar
RichOB
Icon for Post Partisan rankPost Partisan
1 year ago
Solved

Measure/ DAX to filter column by text

Hi, in this example, I have the raw data in Table 1

 

I need to split up the Involvement column so I can add the Victim and Perpetrator as their own columns on the same row.

 

How can I achieve how table 2 looks, please?

 

Table1

Incident_Number Individual IDInvovlementCity Name Type
Inc1ID1PerpetratorLiverpoolDave.DAssuault
Inc1ID2VictimLiverpoolMark.MAssuault
Inc2ID3PerpetratorLiverpoolGrant.GAssuault
Inc2ID4VictimLiverpoolPaul.PAssuault
Inc3ID5PerpetratorLiverpoolAaron.AHarassment
Inc3ID6VictimLiverpoolThomas.THarassment


Table2

Incident_Number CityPerpetrator_NameVictim_NameType
Inc1LiverpoolDave.DMark.MAssault
Inc2LiverpoolGrant.GPaul.PAssault
Inc3LiverpoolAaron.AThomas.TOverdose


Thanks for your help

  • Hi RichOB 

     

    Before performing the Pivot Column step, just add one extra step to remove the nulls from the Involvement column:
    Here's how:
      1. In Power Query, select the Involvement column
      2. Go to the top ribbon >> Filter >> Uncheck (null)
      3. Now try the Pivot Column step again (as before)
    This will ensure Power Query only uses valid text entries ("Victim" / "Perpetrator") and avoids the type conversion error.

4 Replies

  • Hi RichOB 

     

    Power Query Solution (No DAX Needed)
    1. Load your Table1 into Power BI
    2. Go to Transform Data (Power Query)
    3. Select the Name column
    4. Click on Transform >> Pivot Column
    5. For the Values Column, choose "Name"
    6. For the Pivot Column, choose "Involvement"
    7. In the Advanced Options >> Use "Don't Aggregate" (if prompted)
    8. Done! You’ll now see Victim and Perpetrator names as separate columns for each Incident_Number

    • RichOB's avatar
      RichOB
      Icon for Post Partisan rankPost Partisan

      Hi, thanks for your reply. I tried it but it's giving me the error:

      Expression.Error: We cannot convert the value null to type Text.
      Details:
      Value=
      Type=[Type]

      How can I rectify the null entries please?

      • rohit1991's avatar
        rohit1991
        Icon for Super User rankSuper User

        Hi RichOB 

         

        Before performing the Pivot Column step, just add one extra step to remove the nulls from the Involvement column:
        Here's how:
          1. In Power Query, select the Involvement column
          2. Go to the top ribbon >> Filter >> Uncheck (null)
          3. Now try the Pivot Column step again (as before)
        This will ensure Power Query only uses valid text entries ("Victim" / "Perpetrator") and avoids the type conversion error.