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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Difference between two groups in the same column

I have data similar to the following

 

Group

Value

1

25
125
334
334
334
427
427
755
755

 

Essentially, every value in [Group] has the same value in [Value]. Now, I need to use DAX to create a formula column capable of calculating the slope between each represented group. It should work like this:

((Value of Group)-(Value of next lowest Group)) / ((Group)-(Next Lowest Group))

 

Ex: (55-27)/(7-4) = 28/3 = 9.3

     (27-34)/(4-3) = -7/1 = -7

1 ACCEPTED SOLUTION

I created a rank column and a measure like given below

 

Column = RANKX(Sheet1,Sheet1[Group],,DESC,Dense)
Measure = divide(maxx(FILTER(Sheet1,Sheet1[Column]=1),Sheet1[Value])-maxx(FILTER(Sheet1,Sheet1[Column]=2),Sheet1[Value]),maxx(FILTER(Sheet1,Sheet1[Column]=1),Sheet1[Group])-maxx(FILTER(Sheet1,Sheet1[Column]=2),Sheet1[Group]))

 

You can create one more for the second. Unless you were looking for some other display.

 

Link : https://www.dropbox.com/s/p3ewc9h970503qh/groupRank.pbix?dl=0

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
v-eachen-msft
Community Support
Community Support

Hi @Anonymous ,

 

Since each group has the same value, you could create a new table to show single group and value.

Table 2 =
DISTINCT (
    SELECTCOLUMNS ( 'Table', "C1", 'Table'[Group], "C2", 'Table'[Value] )
)

Then create an index column.

Column =
RANKX ( 'Table 2', 'Table 2'[C1],, ASC, DENSE )

Use function to get the value.

Column 2 =
VAR a =
    CALCULATE (
        FIRSTNONBLANK ( 'Table 2'[C1], 1 ),
        FILTER ( 'Table 2', 'Table 2'[Column] = EARLIER ( 'Table 2'[Column] ) - 1 )
    )
VAR b =
    CALCULATE (
        FIRSTNONBLANK ( 'Table 2'[C2], 1 ),
        FILTER ( 'Table 2', 'Table 2'[Column] = EARLIER ( 'Table 2'[Column] ) - 1 )
    )
RETURN
    ROUND ( ( 'Table 2'[C2] - b ) / ( 'Table 2'[C1] - a ), 1 )

1-1.PNG

 Here is my test file for your reference.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.
amitchandak
Super User
Super User

Create a dense rank on group

Follow: https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

 

and the filter on each rank and take a max

divide(maxx(filter(table,rank=4),value),maxx(filter(table,rank=3),value))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
https://community.powerbi.com/t5/Community-Blog/Winner-Topper-on-Map-How-to-Color-States-on-a-Map-wi...
https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...
https://community.powerbi.com/t5/Community-Blog/Power-BI-Working-with-Non-Standard-Time-Periods/ba-p...
https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak I appreciate the suggestion, but this did not work for me. The ranking solution in the article did not provide consistent ranking (ranks jump from 3 to 7 or from 14 to 19) instead of 1, 2, 3, etc. Additionally, there are so many ranks for the groups that the formula provided would not work. I would need to know if there is a way to use DAX to automatically grab the next lowest/highest rank, regardless of the difference between them.

I created a rank column and a measure like given below

 

Column = RANKX(Sheet1,Sheet1[Group],,DESC,Dense)
Measure = divide(maxx(FILTER(Sheet1,Sheet1[Column]=1),Sheet1[Value])-maxx(FILTER(Sheet1,Sheet1[Column]=2),Sheet1[Value]),maxx(FILTER(Sheet1,Sheet1[Column]=1),Sheet1[Group])-maxx(FILTER(Sheet1,Sheet1[Column]=2),Sheet1[Group]))

 

You can create one more for the second. Unless you were looking for some other display.

 

Link : https://www.dropbox.com/s/p3ewc9h970503qh/groupRank.pbix?dl=0

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.