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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Looking to extract only YEARS from specific column

Hello everyone,

Morning!
 

I had a dataset in powerBI, where it looks as follows

 
NumbersExams
1DAX-100-PowerBI-2018-2021
220-DAX-200-PowerBI-2021
3201-DAX-205-powerBI-2019-2020
 
I would like to mention that, every row in Exam's column ends with years and I tried splitting column by delimiter (But, all the data was not in the same format, But all of them ends with years)
 
The result should look like
NumbersExamsYears
1DAX-100-PowerBI-2018-20212018-2021
220-DAX-200-PowerBI-20212021
3201-DAX-205-powerBI-2019-20202019-2020
 
Looking forward for responses.
 
Thank you. 
1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I can clearly understand your requirement, you can try to create a calculated column like this:

Years =

IF(

    ISERROR(left(RIGHT([Exams],6),1)+1),

    RIGHT([Exams],4),

    RIGHT([Exams],9))

And you can get what you want, like this:

vrobertqmsft_0-1635145930751.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your description, I can clearly understand your requirement, you can try to create a calculated column like this:

Years =

IF(

    ISERROR(left(RIGHT([Exams],6),1)+1),

    RIGHT([Exams],4),

    RIGHT([Exams],9))

And you can get what you want, like this:

vrobertqmsft_0-1635145930751.png

 

You can download my test pbix file below

Thank you very much!

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , a new column in DAX

 

Year =

var _pos = search("PowerBI-",[Col],,0)

return

right([Column], len([Column] -(_pos+8))

Anonymous
Not applicable

Hi Amit, 

 

sorry, I didn't get what that mean - could you please elaborate the measure and the measure says that we are searching "PowerBI-". But in my case I will have two different types of text either "PowerBI" or "Power flow". 

Thanks Amit.

@Anonymous , I try to get the location of - after power bi and use that.

What you do first check if it has power bi or power flow and the change logic .

 

ALso this a new measure

 

Year =

var _pos = search("PowerBI-",[Col],,0)

return

if(_pos>0, right([Column], len([Column] -(_pos+8)),  right([Column], len([Column] -(_pos+11)) )

Anonymous
Not applicable

Hi Amit 

 

I am getting an syntax error.


Thank you so much for following up the error. 

Really appreciated-

 

Thanks 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors