Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Add new column with filters based on current row values

My main question here is around how to filter based on a value taken from the current column.

 

In this case I have a column Dates.Month (which is a whole number in the format YYYYMM) and a new calculated column Dates.MonthBefore (which is a whole number in the format YYYYMM, showing the code for the previous month).  So in one row, is the Dates.Month is 202001, then Dates.MonthBefore is 201912.  This bit works OK.

 

How do I create a new column that extracts the value from rows, looking for Dates.Month in the searched rows being equal to Dates.MonthBefore in the current row?  The problem with Filter is it looks at hardcoded values only.

 

I want something like:

 

OpeningBalance = calculate(SUM(Table[Balance]), Table[Dates.Month] = Table[Dates.MonthBefore][thisrow])


I am sure there must be an easy answer to this!

 

Cheers

  • Hi Anonymous ,

     

    Try this:

    Column =
    VAR LastMonth = 'Table'[Dates.BeforeMonth]
    RETURN
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( ALL ( 'Table' ), 'Table'[Dates.Month] = LastMonth )
        )
    

    or,

    Column =
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Dates.Month] = EARLIER ( 'Table'[Dates.BeforeMonth] )
        )
    )
    
    

     

     

    Best Regards,

    Icey

     

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

4 Replies