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
Myagi-Do
Helper I
Helper I

Stuck trying to cathegorize values in a column

I am trying to categorize values (for a lack of better wording) in a column. I want to increase a counter if a new value is detected. 

The "Goal" column is what I am trying to build. I thought of copying values with a -1 shift but I am stuck now on creating a counter and increasing this counter when Values and Custom don't match. Total newbie here 🙂  Any help is appreciated.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEyVIrVIYJpBGIakcw0NTUzB3KMMTkWlkCmCTWYsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Values = _t, #"Goal" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Index",{{"Values", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Range(
   #"Changed Type"[Values],
   [Index]-1,
   1)),
    #"Extracted Values" = Table.TransformColumns(#"Added Custom", {"Custom", each Text.Combine(List.Transform(_, Text.From)), type text}),
    #"Replaced Errors" = Table.ReplaceErrorValues(#"Extracted Values", {{"Custom", null}})
in
    #"Replaced Errors"

 

power bi.png  

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEyVIrVIYJpBGIakcw0NTUzB3KMMTkWlkCmCTWYsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Values = _t, #"Goal" = _t]),
    #"Removed Columns" = Table.RemoveColumns(Source,{"Goal"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Values"}, {{"Temp", each _, type table [Values=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Temp" = Table.ExpandTableColumn(#"Added Index", "Temp", {"Values"}, {"Values.1"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Temp",{"Values.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Index", "Goal"}})
in
    #"Renamed Columns"

 

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRU0lEyVIrVIYJpBGIakcw0NTUzB3KMMTkWlkCmCTWYsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Values = _t, #"Goal" = _t]),
    #"Removed Columns" = Table.RemoveColumns(Source,{"Goal"}),
    #"Grouped Rows" = Table.Group(#"Removed Columns", {"Values"}, {{"Temp", each _, type table [Values=nullable text]}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 1, 1, Int64.Type),
    #"Expanded Temp" = Table.ExpandTableColumn(#"Added Index", "Temp", {"Values"}, {"Values.1"}),
    #"Removed Columns1" = Table.RemoveColumns(#"Expanded Temp",{"Values.1"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns1",{{"Index", "Goal"}})
in
    #"Renamed Columns"

 

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