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

Count of an Occurrence in multiple columns

Hi all,

So I have this dataset as shown in dummy table below.  I need to get a count of each sku and show that it's available in a certain number of outlets. I have split the 'availble_sku' column using the comma delimiter but now I need a DAX/PowerQuery formula to get that count.

Outlet idavailable_sku
33sku1,sku3
44sku2
77sku2,sku3,sku1,sku4,sku5
56sku3,sku4
23sku5
12sku6,sku5

My Desired output is as below:

available_skusNo of Outlets
sku12
sku22
sku33
sku42
sku53
sku61

Any assistance to solving this, will be highly appreciated. Thank you.

2 ACCEPTED SOLUTIONS
HotChilli
Super User
Super User

After the 'split by delimiter' in Power Query, select the first column and 'Unpivot other columns'.

Close and Apply

Create a table visual with the SKU's in the first column, put COUNT of outlets in the 2nd column

View solution in original post

Vera_33
Resident Rockstar
Resident Rockstar

Hi @Kaskazi_Network 

 

If you want to use Power Query, put below M code in Advanced Editor with a blank query. If you want to use DAX, you can stay with step #"Expanded available_sku", then simply use COUNTROWS

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZW0lEqzi411AESxkqxOtFKJiYQISMwz9wcygMr0IEpNQERpmAVpmYQFWBJE7CQEdRUiAJDIwjPDKonFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Outlet id" = _t, available_sku = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Outlet id", Int64.Type}, {"available_sku", type text}}),
Custom1 = Table.TransformColumns( #"Changed Type",{"available_sku", each Text.Split(_,",")}),
#"Expanded available_sku" = Table.ExpandListColumn(Custom1, "available_sku"),
#"Grouped Rows" = Table.Group(#"Expanded available_sku", {"available_sku"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"

View solution in original post

2 REPLIES 2
Vera_33
Resident Rockstar
Resident Rockstar

Hi @Kaskazi_Network 

 

If you want to use Power Query, put below M code in Advanced Editor with a blank query. If you want to use DAX, you can stay with step #"Expanded available_sku", then simply use COUNTROWS

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZW0lEqzi411AESxkqxOtFKJiYQISMwz9wcygMr0IEpNQERpmAVpmYQFWBJE7CQEdRUiAJDIwjPDKonFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Outlet id" = _t, available_sku = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Outlet id", Int64.Type}, {"available_sku", type text}}),
Custom1 = Table.TransformColumns( #"Changed Type",{"available_sku", each Text.Split(_,",")}),
#"Expanded available_sku" = Table.ExpandListColumn(Custom1, "available_sku"),
#"Grouped Rows" = Table.Group(#"Expanded available_sku", {"available_sku"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"

HotChilli
Super User
Super User

After the 'split by delimiter' in Power Query, select the first column and 'Unpivot other columns'.

Close and Apply

Create a table visual with the SKU's in the first column, put COUNT of outlets in the 2nd column

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
Top Kudoed Authors