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

HELP INDEX COLUMN WITH RANGES

I have a two columns "JOB" and "ROL", Job is a incremental number and "ROL" this could be "A","B" or "C". And I would like to add a column like index considering how many equals roles there are for each job, as the folowing example:

 

 
JOBROLINDEX RESULT
1A1
1A2
1B1
1C1
2A1
2B1
2C1
3A1
3B1
3B2
3B3
3C1
 
5 REPLIES 5
Mariusz
Community Champion
Community Champion

Hi @abelrmg 

 

You can try something like below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXJUitVBZznBWc5glhFc1gguawSXNYbLGsNlcbGAOmIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [JOB = _t, ROL = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"JOB", Int64.Type}, {"ROL", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"JOB", "ROL"}, {{"Index", each Table.AddIndexColumn( _, "Index", 1 )[Index], type list }}),
    #"Expanded Index" = Table.ExpandListColumn(#"Grouped Rows", "Index"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Index",{{"Index", Int64.Type}})
in
    #"Changed Type1"

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

parry2k
Super User
Super User

@abelrmg add an index column in query editor and then add following column and it will get you what you are looking for

 

 

Index Result = 
RANKX ( 
FILTER(  
What, 
What[Job]= EARLIER ( What[Job] )  && 
What[ROL] = EARLIER ( What[ROL] )  
), 
What[Index], , ASC, Dense 
)

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k , thank you for your suggestion it works, but is there sometihing similar in Power Query?, beacuse then i want to create a pivot table and the values are dynamics and this does not work in DAX.

 

Regards

Not sure what you mean by dynamic, it should work. May be I am missing something.


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k It was my mistake, I forgot to mention that I was looking for the solution via Power Query, because then I will use that column to make a pivot table to perform some like this:

 

JobROL A1ROL A2ROL B1ROL B2ROL B3ROL C1
1Name 1Name 2Name 3  Name 4
2NAME 5 NAME 6  NAME 7
3NAME 8 NAME 9NAME 10NAME 11NAME 12

 

 

Regards

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.