Forum Discussion

fab196's avatar
fab196
Helper II
4 years ago
Solved

Sum OF values

Hi Everyone ,

 

need your help

i want use power query and generate the result below

 

I have with two columns first is original col and second one is derived column as mentioned the below

i want to amke a running toatl but in different way

in the example listed below if the values are not macthing from both columns a and b then the deafualt value is will 1 in the result col

if the values are macthing then it should be add 1 to each values

AB  result 
1NULL initial  value is nulll then it should be 1(in short values are not matching)1
11 it is matching so added above value 1+ 12
21 both values are not macthing so 1
22 macthing then adding above 1+12
22 macthing so above 2+13
32 not macthing so 11
43 not macthing so 11
44 macthing so above 1 value and add 1 into that so 1+12

 amitchandak 

parry2k 

v-luwang-msft 

 

  • fab196 , a new column

     

    new column =

    vat _b = [B]+0

    return

    countx(filter(Table, [A] = earlier([A]) && [B]+0 <= +b ), [A])

  • Hi fab196 ,

    According to your description, it's more easier to achieve it by DAX, here's my solution.

    1.In Power Query, add an index column.

    Get this table.

    2.Create a calculated column.

    Count =
    VAR _RANK =
        RANKX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[ColumnA] = EARLIER ( 'Table'[ColumnA] )
                    && 'Table'[ColumnB] = EARLIER ( 'Table'[ColumnB] )
                    && 'Table'[ColumnA] = 'Table'[ColumnB]
            ),
            'Table'[Index],
            ,
            ASC,
            DENSE
        )
    RETURN
        IF ( 'Table'[ColumnA] = 'Table'[ColumnB], _RANK + 1, _RANK )
    

    Get the expected result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

5 Replies

  • fab196 , a new column

     

    new column =

    vat _b = [B]+0

    return

    countx(filter(Table, [A] = earlier([A]) && [B]+0 <= +b ), [A])

  • Hi fab196 ,

    According to your description, it's more easier to achieve it by DAX, here's my solution.

    1.In Power Query, add an index column.

    Get this table.

    2.Create a calculated column.

    Count =
    VAR _RANK =
        RANKX (
            FILTER (
                ALL ( 'Table' ),
                'Table'[ColumnA] = EARLIER ( 'Table'[ColumnA] )
                    && 'Table'[ColumnB] = EARLIER ( 'Table'[ColumnB] )
                    && 'Table'[ColumnA] = 'Table'[ColumnB]
            ),
            'Table'[Index],
            ,
            ASC,
            DENSE
        )
    RETURN
        IF ( 'Table'[ColumnA] = 'Table'[ColumnB], _RANK + 1, _RANK )
    

    Get the expected result.

    I attach my sample below for reference.

     

    Best Regards,
    Community Support Team _ kalyj

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.