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
fraza
Frequent Visitor

Calculated Index column based on groups

Can anyone help me with this.?

 

WhatsApp Image 2021-09-28 at 18.36.20.jpeg

 

I need make the calculated column on the right hand side that only increments when the original field changes its value.

 

Noticed that the increments should keep increasing even though the a original group value may repeat the index should not.

 

Is there an option or some dax etc to achieve this?

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@fraza 

This is logically not possible since you don't have a field to group by. As the workaround, you could add an index column and flag column before getting the rank, which is a bit confusing.

 

1. add an index column in power query

2. create a flag column 

Flag =
var current_=[Original]
var current_1= CALCULATE(MAX([Original]),FILTER('Table',[Index]=EARLIER([Index])-1))
var current_2 = CALCULATE(MAX([Original]),FILTER('Table',[Index]=EARLIER([Index])-2))
var index_1=CALCULATE(SUM('Table'[Index]),FILTER('Table',[Index]=EARLIER([Index])-1))
var index_2=CALCULATE(SUM('Table'[Index]),FILTER('Table',[Index]=EARLIER([Index])-2))
Return
IF(current_=current_1&&current_1=current_2,index_2,IF(current_=current_1,index_1,[Index]))
 
3. create the rank column

Vpazhenmsft_0-1633055760558.png

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
V-pazhen-msft
Community Support
Community Support

@fraza 

This is logically not possible since you don't have a field to group by. As the workaround, you could add an index column and flag column before getting the rank, which is a bit confusing.

 

1. add an index column in power query

2. create a flag column 

Flag =
var current_=[Original]
var current_1= CALCULATE(MAX([Original]),FILTER('Table',[Index]=EARLIER([Index])-1))
var current_2 = CALCULATE(MAX([Original]),FILTER('Table',[Index]=EARLIER([Index])-2))
var index_1=CALCULATE(SUM('Table'[Index]),FILTER('Table',[Index]=EARLIER([Index])-1))
var index_2=CALCULATE(SUM('Table'[Index]),FILTER('Table',[Index]=EARLIER([Index])-2))
Return
IF(current_=current_1&&current_1=current_2,index_2,IF(current_=current_1,index_1,[Index]))
 
3. create the rank column

Vpazhenmsft_0-1633055760558.png

 

Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

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.