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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
therugger2000
New Member

Another If statement

I am attempting extract text from a column based on another column.

Basically if the value from column1 =1, return the first 3 characters in Column 2, if not return rthe first 2.

 

Example of Column1 info : 1 or 2

Column2 Info: 1234abcd

 

new=IF Column1="1", LEFT(table1[column2],3, LEFT(table1[column2],2

Any help is appreciated.

1 ACCEPTED SOLUTION
AnkitKukreja
Super User
Super User

Hi! @therugger2000 

 

Please use the below m code and it should work for you.

 

Col1      Col2       Extraction

1 123abs 123
2 145grbf 14
3 345 34
1 111ggg 111
2 2334 23
1 2332mmm 233
2 233mmm 23

 

if [Col1] = 1 then Text.Middle ([Col2],0,3)
else
Text.Middle ([Col2],0,2)

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
https://topmate.io/ankit_kukreja/

View solution in original post

1 REPLY 1
AnkitKukreja
Super User
Super User

Hi! @therugger2000 

 

Please use the below m code and it should work for you.

 

Col1      Col2       Extraction

1 123abs 123
2 145grbf 14
3 345 34
1 111ggg 111
2 2334 23
1 2332mmm 233
2 233mmm 23

 

if [Col1] = 1 then Text.Middle ([Col2],0,3)
else
Text.Middle ([Col2],0,2)

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904
https://topmate.io/ankit_kukreja/

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors