Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Visualize costs dynamically

Hi,   I have two columns which are costs and period. The period ranges from 2018 Jan to 2020 Jan. Each month I add new column to the excel source with new date and cost. I want to visualize the las...
  • v-lionel-msft's avatar
    v-lionel-msft
    6 years ago

    Anonymous,

     

    I have a way.
    First sort [Period] column in ascending order, then, add a [index] column in Edit Queries.

    Second, create measures:

    Last12 = 
    VAR x = 
    CALCULATE(
        MAX(Sheet1[Index]),
        ALL(Sheet1)
    )
    RETURN
    CALCULATE(
        MAX(Sheet1[Costs]),
        FILTER(
            Sheet1,
            [Index] <= x && [Index] >= x-12
    ))
    
    Last12 - Last 24 = 
    VAR x = 
    CALCULATE(
        MAX(Sheet1[Index]),
        ALL(Sheet1)
    )
    RETURN
    CALCULATE(
        MAX(Sheet1[Costs]),
        FILTER(
            Sheet1,
            [Index] <= x-12 && [Index] >= x-24
    ))

    As your data source's rows increase, the [Index] column will automatically increase, so the result is still right.

     

    Best regards,
    Lionel Chen

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