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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Will38
Frequent Visitor

how can I count all numbers under 15 across 5 columns that were split by a comma delim in Power BI?

I have a column that imported from a database where childrens ages where in a text field seperated by a comma.  I spilt the column by the deliminator and now have 5 columns.  I need to count all children under the age of 15.  I have tried using counta with a filter and the result was not accurate.  Any other suggestions?

Will38_0-1662756117901.png

 

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

=let a=List.Select(Table.ColumNames(PreviousStepName),each Text.StartsWith(_,"ClientCustom_ChildrenAges")) in Table.AddColumn(PreviousStepName,"AgeLessThan15",each List.Count(List.Select(Record.ToList(Record.SelectFields(_,a)),each Number.From("0"&_)<15)))

View solution in original post

6 REPLIES 6
wdx223_Daniel
Super User
Super User

=let a=List.Select(Table.ColumNames(PreviousStepName),each Text.StartsWith(_,"ClientCustom_ChildrenAges")) in Table.AddColumn(PreviousStepName,"AgeLessThan15",each List.Count(List.Select(Record.ToList(Record.SelectFields(_,a)),each Number.From("0"&_)<15)))

ronrsnfld
Super User
Super User

Consider splitting by the delimiter into Rows instead of columns; then counting the number <15 is simpler

AlexisOlson
Super User
Super User

Unpivot those columns and then filter for < 15.

 

Here's a simplified example that you can paste into the Advanced Editor of a new blank query.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIDYksgNjRSitUBCoHEDE2ABAiBRcygHBjfGIkfCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", Int64.Type}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {}, "Attribute", "Value"),
    #"Filtered Rows" = Table.SelectRows(#"Unpivoted Columns", each [Value] < 15),
    #"Count Rows" = Table.RowCount(#"Filtered Rows")
in
    #"Count Rows"

 

Starting with

AlexisOlson_0-1662763229920.png

Unpivoting results in this:

AlexisOlson_1-1662763260751.png

 

This format makes it easy to count values less than 15 either in the query editor or with DAX.

Thank you very much for your response.  I only copied the 4 columns that I am trying to count when asking this question.  There are 10 other columns as part of this table.  How will unpivoting these effect the other columns.  There is a comparison of this count and another count in the columns not shown in my question. 

You should only unpivot the columns you want to do the counting over.

 

If your table started like this:

AlexisOlson_0-1662998087331.png

Then unpivoting the last four columns would look like this:

 

AlexisOlson_1-1662998117440.png

Thank you

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors