Forum Discussion

tgjones43's avatar
tgjones43
Helper IV
7 years ago
Solved

Pivot query

Hello. Please can someone advise how I can go from the first table to the second table? Each number, in column A, has a name in column B and occupies one to several rows depending on how many parameters are associated with that Number/Name. I would like to pivot by column C, and provide a Yes value in the relevent columns where each parameter occurs for each Number/Name.

Thank you.

 

  

NumberNameParameter    
1AA      
1AB      
2BA      
2BB      
2BC      
3CC      
3CD      
4DB      
4DC      
4DD      
4DE      
5EC      
5ED      
5EE      
5EF      
5EG      
         
NumberNameABCDEFG
1AYesYes     
2BYesYesYes    
3C  YesYes   
4D YesYesYesYes  
5E   YesYesYesYes
  • Hi,

     

    This M code works

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Number", Int64.Type}, {"Name", type text}, {"Parameter", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "Yes"),
        #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Parameter]), "Parameter", "Custom")
    in
        #"Pivoted Column"

6 Replies

  • Hi,

     

    This M code works

     

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Number", Int64.Type}, {"Name", type text}, {"Parameter", type text}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each "Yes"),
        #"Pivoted Column" = Table.Pivot(#"Added Custom", List.Distinct(#"Added Custom"[Parameter]), "Parameter", "Custom")
    in
        #"Pivoted Column"

  • Hi tg you can drop the number and number on the rows of a matrix and the Parameter on the column and then use =IF(countrows(tablename) > 0, "YES", blank() )
      • LivioLanzo's avatar
        LivioLanzo
        Solution Sage

        Hi tgjones43

         

        it is possible to do it within Power Query but it would require more steps and be less efficient