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
NPC
Helper I
Helper I

Extract specific numbers from a group

Hello,

 

Hope you can help with this.

 

I have a table that looks like this:

Transaction IDExtracts
1021, 003, 022, 603, 415
2002, 001, 408, 510
3005, 004, 006, 510, 415, 408

 

From the Extracts column, I care about the last number (to the right) if its one of the following: 001, 002, 003, 004, 005, 006. All the other ones are irrelevant. 

 

So at the end, for Transcation ID 1, the number I would need is 003. 

For Transcation ID 2, 001.

For Transcation ID 3, 006.

 

The order of the number is very important and need to be mantained. And as you can see, there is no easy way to predict how many each Transaction ID will have. It could be 5, 1 or even up to 10. 

 

Thanks  you!

1 ACCEPTED SOLUTION
Shaurya
Memorable Member
Memorable Member

Hi @NPC,

 

You can extract these specific numbers from a group by using list functions.

 

Create a custom column using this M Code:

 

 

Extract = List.Last(List.Select(Text.Split([Extracts],","), each _ <= "006"))

 

 

This code will:

  1. Convert your group into a list.
  2. Filter out everything except {001..006}.
  3. Return the right most element from that list.

 

In case you don't have any number from 001 to 006 in your group, you'll get a null value.

 

Screenshot 2022-10-04 050921.jpg

 

Works for you? Mark this post as a solution if it does!

View solution in original post

6 REPLIES 6
NPC
Helper I
Helper I

I'll remove the square brackets and see what happens. Thanks!

Shaurya
Memorable Member
Memorable Member

Let me know if that works or not...

The square brackets were causing issues. Thank you so much!

Shaurya
Memorable Member
Memorable Member

Hi @NPC,

 

You can extract these specific numbers from a group by using list functions.

 

Create a custom column using this M Code:

 

 

Extract = List.Last(List.Select(Text.Split([Extracts],","), each _ <= "006"))

 

 

This code will:

  1. Convert your group into a list.
  2. Filter out everything except {001..006}.
  3. Return the right most element from that list.

 

In case you don't have any number from 001 to 006 in your group, you'll get a null value.

 

Screenshot 2022-10-04 050921.jpg

 

Works for you? Mark this post as a solution if it does!

@Shaurya Thank you! It works it some cases but not in all for some reason. As you can see below, instead of pulling 004, it pulled 209. Any thoughts as to why that's happening? The new column I created is " Exracted Latest Scenarion". Ignore the date column. 

 

NPC_0-1664905858469.png

Thanks!

Shaurya
Memorable Member
Memorable Member

Hi @NPC,

 

I think this is because of the square brackets. The original column in your post had only comma separated values. However in the second case where you got the wrong output, the values are separated by comma but also enclosed in brackets. Can you check if you get any wrong values at all in the first case?

 

As far as the second case is concerned, if you can specify the different ways in which the Extract column may have values, we can work out a solution that gives the right values in all cases.

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.