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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Conditional Index with Maximum Value

Hi everyone! I have been searching the forum for conditional index solutions but I can't seem to find any which matches my problem. It seems fairly simple yet I wasn't able to combine ideas from provided solutions (such as usage of VAR/MAX).

 

The key column looks up from another table so it is static (abc MAX is always 3, def MAX is always 2, so on).

I need to create a new index column based on KEY which restarts to 1 once it reaches its max value.

 

KEYMAXINDEX
abc31
abc32
def21
def22
abc33
abc31
def21
ghi41
ghi42
ghi43
ghi44
def22

 

Thanks in advance!

1 ACCEPTED SOLUTION

@Anonymous 

you can create an index table in PQ, then use DAX to create a column

Column = 
if(mod(CALCULATE(COUNTROWS('Table'),'Table'[KEY]=EARLIER('Table'[KEY])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[MAX])=0,'Table'[MAX],mod(CALCULATE(COUNTROWS('Table'),'Table'[KEY]=EARLIER('Table'[KEY])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[MAX]))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

8 REPLIES 8
MyroslavaM
Advocate II
Advocate II

Hi @k_rojvanakarn , @ryan_mayu , @Anonymous 

Might be useful for you.
Picture (1).png
In this case, I generate values from 1 to 5 and repeting them based on Index column.

= List.Accumulate(#"Added Index"[Index],{0}, (state,current) =>  
    if current = 0 then {1} 
    else if List.Last(state)>4 then
    state &{List.Last(state)-4} else state & {List.Last(state)+1})

Here is a good video related how to use other approach https://youtu.be/Hc3d8rMSXcQ?si=S1Adls_HbrgPn4bw

Ashish_Mathur
Super User
Super User

Hi,

How did you arrive at the numbers in the Index column?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
ryan_mayu
Super User
Super User

@Anonymous 

is this a table or a visual?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Hi! This is in a table

@Anonymous 

you can create an index table in PQ, then use DAX to create a column

Column = 
if(mod(CALCULATE(COUNTROWS('Table'),'Table'[KEY]=EARLIER('Table'[KEY])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[MAX])=0,'Table'[MAX],mod(CALCULATE(COUNTROWS('Table'),'Table'[KEY]=EARLIER('Table'[KEY])&&'Table'[Index]<=EARLIER('Table'[Index])),'Table'[MAX]))

1.PNG

pls see the attachment below





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




is this possible in the power query editor? i have the sane structure but in power query instead of columns and measures..

Anonymous
Not applicable

Thanks! Works exactly as intended. Just having memory related problems once this is applied to a table with 50k+ rows, so I may have to recreate this in PQ instead of DAX

 

Appreciate the help!

I don't know how to do this in PQ, let's see if anyone else can help on M language.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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