Find rows relative to current row's value in excel (DAX)

后端 未结 3 942
不思量自难忘°
不思量自难忘° 2021-01-22 08:51

Is there a way to filter rows based on your current row\'s value using DAX (I\'m using power pivot) ?

In other words, If I had a table \"progress\" with \'ID\' that is i

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-22 09:24

    An alternative to Petr's elegant solution is to approach this using a measure.

    Which is best in this case will depend on the specifics of your model, the size of your table, how often you will use this calculation and how many times you will want to replicate it (i.e. if you wanted to add 10 calc columns, that would be a bad idea).

    I like the measure approach because it uses a very re-usable pattern:

    =
    SUMX (
        VALUES ( Progress[ID] ),
        CALCULATE (
            SUM ( Progress[PERCENTAGE] ),
            FILTER (
                ALL ( Progress ),
                Progress[ID]
                    = MAX ( Progress[ID] ) - 1
            )
        )
    )
    

    Be careful of totals using this method - turning them off is probably the 'right' thing to do.

    Formula prettified using Dax Formatter

提交回复
热议问题