Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jeongkim
Post Prodigy
Post Prodigy

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. 

 

jeongkim_0-1712561098582.png

 

Please help. 

2 ACCEPTED SOLUTIONS
ryan_mayu
Super User
Super User

@jeongkim 

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

 

11.PNG

 

then select the new column and fill down

12.PNG

13.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

you can change to 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

7 REPLIES 7
ryan_mayu
Super User
Super User

@jeongkim 

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

 

11.PNG

 

then select the new column and fill down

12.PNG

13.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi,

 

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

 

you can change to 

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





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks!

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks! accpeted. 

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors