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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

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

@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

 

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

@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

 

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!




Anonymous
Not applicable

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!




Anonymous
Not applicable

Thanks!

you are welcome





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

Proud to be a Super User!




Anonymous
Not applicable

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors