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
shekhar_shres
Helper II
Helper II

Categorising a Column based on Row Count

Hi all,

I hope all of you are having a great time. I need a help with Power Query.

I have the following Column.

shekhar_shres_0-1619926688765.png

I want to add a Category Column that depends on row as below. For example, the First 3 rows Category 1, row 3 to 6 Category 2 and so on. A business rule is that the category should increase after every 3 rows. 

shekhar_shres_1-1619926835219.png

How can I achieve this in Power Query?

Thanks in Advance



 

1 ACCEPTED SOLUTION

Simply adding 1 would solve it

 

Table.AddColumn(Source, "Category", each "Category " & Number.ToText(Number.RoundDown(List.PositionOf(Source[ID],[ID])/3)+1))

View solution in original post

4 REPLIES 4
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlGK1YlWMgWTZmDSHExagElLMGloAKEMIZSRUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
    Custom1 = Table.AddColumn(#"Changed Type", "New", each "Category " & Text.From(Number.IntegerDivide([ID]-1, 3)))
in
    Custom1

Screenshot 2021-05-02 113020.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Jakinta
Solution Sage
Solution Sage

Hi,

 

Paste this into your next step and replace Source with previous one.

 

Categorized = Table.AddColumn(Source, "Category", each "Category " & Number.ToText(Number.RoundDown(List.PositionOf(Source[ID],[ID])/3)))

It started from 0 instead of 1 when I used the code. 

shekhar_shres_0-1619942497345.png


When I included Roundup, it came as follows:

shekhar_shres_1-1619942536130.png


We were close enough



Thankyou,



Simply adding 1 would solve it

 

Table.AddColumn(Source, "Category", each "Category " & Number.ToText(Number.RoundDown(List.PositionOf(Source[ID],[ID])/3)+1))

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