Forum Discussion

vin26's avatar
vin26
Icon for Resolver I rankResolver I
1 year ago
Solved

Get the Max Available Month on Selection

Hello,   I am trying to calculate average of value for last 6 months by skipping selected month. When I select a specific month if the data exist for the specific employee in the selected month I a...
  • rajendraongole1's avatar
    1 year ago

    Hi vin26 -Create a Measure to Get the Max Available Month for Each Employee

     

    Max Available Month =
    CALCULATE(
    MAX(Table1[Month]),
    FILTER(
    ALL(Table1),
    Table1[EMP ID] = MAX(Table1[EMP ID]) && Table1[Month] <= MAX('DimDate'[Month])
    )
    )

     

    Measure for last 6 months calc.

    Average Last 6 Months =
    CALCULATE(
    AVERAGE(Table1[Amount]),
    DATESINPERIOD(
    'DimDate'[Month],
    [Max Available Month],
    -6,
    MONTH
    ),
    Table1[Amount] <> BLANK()
    )

     

    check with above measures, if still issue exist please share the pbix file by removing the sensitive data.

  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi vin26 

     

    Please try this:
    Maybe you can delete the relationship between the Table1 and the DimDate:

    Then add a measure:

     

    MEASURE =
    VAR _slicer =
        MONTH ( MAX ( 'DimDate'[Month] ) )
    RETURN
        CALCULATE (
            AVERAGE ( 'Table'[Amount] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                MONTH ( 'Table'[Month] ) < _slicer
                    && MONTH ( 'Table'[Month] ) >= _slicer - 6
            )
        )
    

     

    Then add a slicer with DimDate[Month]:

    The result is as follow:

     

    Best Regards

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