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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Danielnir
Helper II
Helper II

Extract values from a text, based on condition

Hi,

 

I have a dataset with item descriptions. Within those, there is information about volumes. How to extract just them? 

Sample photo showing how the description works:

 

Danielnir_0-1660218170760.png

 

As you can see, volume data can be placed randomly within the descriptions. Also, it can be "L" for litres instead of "ml" but it's optional to include in the solution. It might be a calculated column written in Dax if there's no other option.

 

May I ask for your assistance?

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Assuming the column name is Data, use below formula in a custom column

= List.Select(Text.Split([Data]," "),(x)=> try Value.Is(Number.From(Text.Split(Text.Replace(Text.Lower(x),"ml","l"),"l"){0}), type number) otherwise false and Text.Split(Text.Replace(Text.Lower(x),"ml","l"),"l"){1}=""){0}

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs5JTcwrTlVwS0xOVQhPLM5QMDIwyM1R8A9yVYrViVbySMxLUXAuSk3MVTAFioPFggPcjA0UfPJLMvPzwKIKugpu/kEKvv4uYPlksHIjM3MfhZLyUrCQhamBr48CWEIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Data = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each List.Select(Text.Split([Data]," "),(x)=> try Value.Is(Number.From(Text.Split(Text.Replace(Text.Lower(x),"ml","l"),"l"){0}), type number) otherwise false and Text.Split(Text.Replace(Text.Lower(x),"ml","l"),"l"){1}=""){0}, type text)
in
    #"Added Custom"

 

I'd recommend using List.First instead of {0} to avoid errors if the list is empty.

 

Here's a slightly simpler version:

List.First(
    List.Select(
        Text.Split([Data]," "), each
            try Value.Is(Number.From(Text.Remove(Text.Lower(_), {"m","l"})), type number)
            otherwise false
    )
)

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors