Forum Discussion
Extract specific numbers from a group
- 3 years ago
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:
- Convert your group into a list.
- Filter out everything except {001..006}.
- 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.
Works for you? Mark this post as a solution if it does!
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:
- Convert your group into a list.
- Filter out everything except {001..006}.
- 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.
Works for you? Mark this post as a solution if it does!
- NPC3 years ago
Helper I
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.
Thanks!
- Shaurya3 years ago
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.