Share via

Power query formula for adjusting rounding in 2 columns

Roshan Tellis 0 Reputation points
2026-01-10T14:04:06.22+00:00

Hi All

I have this basic power query file that takes the input (same amount as debit) and divides the amount into each line and gives output based on percentage allocated on a table (the "credit" which are 14 stores).

The issue comes due to rounding done in the power query editor that leads to penny variances.

I need to make sure that the sum of "debits" and "credits" are matching always in order to remove the need for manual adjustment when copy pasting in dynamics. We can do that by adjusting the first line but I do not know how to derive a formula that does so.

Also the number of stores will increase with time so the formula must capture the new lines which will be added in the stores table in the future in order to have the sum of both lines to be equal.

I have another generator which does this with multiple amount so I will be able to carry over the formula there as well once we get this sorted.

Kindly also suggest any videos or features of power query so I can engage in self learning and arrive at a solution myself if you are unable to support directly.

Thanks.

User's imageUser's image

Microsoft 365 and Office | Excel | For business | Windows
{count} votes

1 answer

Sort by: Most helpful
  1. Marcin Policht 82,930 Reputation points MVP Volunteer Moderator
    2026-01-10T16:00:25.8166667+00:00

    After you calculate the credit split for each store, Power Query must correct the small rounding differences. Probably the safest way to do this would be to add the total rounding difference back into the first record. This requires no hard-coding of the number of stores and automatically works when new stores are added. The process is: add an index, calculate the rounding variance, add the variance to the first row only, then remove the helper index.

    From the Power Query M formula perspective, this means replacing PrevStepName with the name of the step that produces your rounded Credit column and replacing RawCredit if your unrounded values use a different name.

    let
        Source = PrevStepName,
    
        AddIndex = 
            Table.AddIndexColumn(Source,"AdjIndex",0,1),
    
        SumRounded = 
            List.Sum(AddIndex[Credit]),
    
        SumRaw = 
            List.Sum(AddIndex[RawCredit]),
    
        DebitAmount = 
            SumRaw,
    
        Variance = 
            DebitAmount - SumRounded,
    
        AdjustCredit =
            Table.TransformColumns(
                AddIndex,
                {
                    {
                        "Credit",
                        each if [AdjIndex]=0 then _ + Variance else _,
                        type number
                    }
                }
            ),
    
        RemoveIndex = 
            Table.RemoveColumns(AdjustCredit,{"AdjIndex"})
    in
        RemoveIndex
    

    This way the total of Credit after this step should always equal the Debit amount. The adjustment should work regardless of how many stores exist now or are added later.


    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.