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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
roalisco
Frequent Visitor

How to calculate percentage change by groups?

Hi everyone, 
Firs time posting a quetion here....
I have the following dataset where my Index column resets for each check_id:

check_idok_rowsIndex
111211
111282
111243
11131001
11131002
1113503
11131004

 

I want to calculate (in DAX or Power Query) the percent change of every check_id from its previous (i.e. Index) value, so that I can have the following output:

check_idok_rowsIndex%_change
111281 
1112162100%
111243-75%
11131001 
111310020%
1113503-50%
11131004100%


I appreciate any help with this. 
Many thanks in advance,
 

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @roalisco - you can check below @bhanu_gautam suggested via Power query 

adding to the sme i have checked via calculated column in dax, 

%_change =
VAR CurrentValue = 'rowch'[ok_rows]
VAR PreviousValue =
    CALCULATE(
        MAX('rowch'[ok_rows]),
        FILTER(
            'rowch',
            'rowch'[check_id] = EARLIER('rowch'[check_id]) &&
            'rowch'[Index] = EARLIER('rowch'[Index]) - 1
        )
    )
RETURN
IF(
    ISBLANK(PreviousValue),
    BLANK(),
    DIVIDE(CurrentValue - PreviousValue, PreviousValue, 0)
)

rajendraongole1_0-1725878291775.png

 

you can try 

Hope it helps.

 





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

Proud to be a Super User!





View solution in original post

4 REPLIES 4
ThxAlot
Super User
Super User

%_change = 
VAR __prv =
    SELECTCOLUMNS(
        OFFSET(
            -1,
            ALLSELECTED( DATA[check_id], DATA[Index], DATA[ok_rows] ),
            ORDERBY( DATA[Index] ),
            PARTITIONBY( DATA[check_id] )
        ),
        DATA[ok_rows]
    )
RETURN
    IF( NOT ISBLANK( __prv ), DATA[ok_rows] / __prv - 1 )

ThxAlot_0-1725888800862.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



rajendraongole1
Super User
Super User

Hi @roalisco - you can check below @bhanu_gautam suggested via Power query 

adding to the sme i have checked via calculated column in dax, 

%_change =
VAR CurrentValue = 'rowch'[ok_rows]
VAR PreviousValue =
    CALCULATE(
        MAX('rowch'[ok_rows]),
        FILTER(
            'rowch',
            'rowch'[check_id] = EARLIER('rowch'[check_id]) &&
            'rowch'[Index] = EARLIER('rowch'[Index]) - 1
        )
    )
RETURN
IF(
    ISBLANK(PreviousValue),
    BLANK(),
    DIVIDE(CurrentValue - PreviousValue, PreviousValue, 0)
)

rajendraongole1_0-1725878291775.png

 

you can try 

Hope it helps.

 





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

Proud to be a Super User!





Many thanks!

bhanu_gautam
Super User
Super User

@roalisco , Try below mentioned m-code for Power Query

 

let
Source = YourDataSource,
SortedRows = Table.Sort(Source,{{"check_id", Order.Ascending}, {"Index", Order.Ascending}}),
AddedIndex = Table.AddIndexColumn(SortedRows, "Index1", 0, 1, Int64.Type),
AddedPreviousValue = Table.AddColumn(AddedIndex, "PreviousValue", each try if [Index1] = 0 then null else AddedIndex{[Index1]-1}[ok_rows] otherwise null),
AddedPercentChange = Table.AddColumn(AddedPreviousValue, "%_change", each if [PreviousValue] = null then null else ([ok_rows] - [PreviousValue]) / [PreviousValue]),
RemovedColumns = Table.RemoveColumns(AddedPercentChange,{"Index1", "PreviousValue"})
in
RemovedColumns




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors