Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Add column to get particular value and fill down in Query M code

Hi,

 

I hope to make a new column in Query using M code like below:

To give Quarter number attribute to all row values. 

 

 

Please help. 

  • Anonymous 

    maybe you can try this

    1. add a new column

    =if Text.Contains([comments],"Q1") or Text.Contains([comments],"Q2") or Text.Contains([comments],"Q3") or Text.Contains([comments],"Q4") then [comments] else null

     

     

    then select the new column and fill down

  • you can change to 

    =if [comments]="Q1"or [comments]="Q2" or [comments]="Q3" or [comments]="Q4"  then [comments] else null

7 Replies

  • Anonymous 

    maybe you can try this

    1. add a new column

    =if Text.Contains([comments],"Q1") or Text.Contains([comments],"Q2") or Text.Contains([comments],"Q3") or Text.Contains([comments],"Q4") then [comments] else null

     

     

    then select the new column and fill down

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks! accpeted. 

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

       

      As to Text.Contains, can we change M code to exact Q1~Q4 value not contains? 

       

      • ryan_mayu's avatar
        ryan_mayu
        Super User

        you can change to 

        =if [comments]="Q1"or [comments]="Q2" or [comments]="Q3" or [comments]="Q4"  then [comments] else null