Forum Discussion

LWJ2019's avatar
LWJ2019
New Member
2 years ago

Average function causing measure calculation out of desired date period

Hi, 

I have issue with below measure.

I need to calculate the average within the date range but whenver i use AVERAGE function, it doesn't work!

How can i modify below measure?

 

AVGCCSA_Q =
VAR SelectedYearMonth = SELECTEDVALUE('Slicer'[YYYYMM])
VAR _seldatenum =
    CALCULATE (
        MAX('FactFINData'[Dnum]),
        FILTER (
            ALLSELECTED('FactFINData'),
            'FactFINData'[YYYYMM] = SelectedYearMonth
        )
    )
VAR _startDNum = _seldatenum -
    SWITCH(
        INT(RIGHT(_seldatenum, 2)),
        10, 100,
        11, 101,
        12, 102,
        1, 191,
        2, 192,
        3, 193,
        4, 194,
        5, 195,
        6, 196,
        7, 197,
        8, 198,
        9, 199,
        0  
    )
VAR _endDNum = _seldatenum -
    SWITCH(
        INT(RIGHT(_seldatenum, 2)),
        10, 1,
        11, 2,
        12, 3,
        1, 92,
        2, 93,
        3, 94,
        4, 95,
        5, 96,
        6, 97,
        7, 98,
        8, 99,
        9, 100,
        0 
    )
RETURN
CALCULATE (
        AVERAGE ( DimSalesPercentage[SalesAmountCC] ),
        DimSalesPercentage[cost_ctr] = SELECTEDVALUE ( FactFINData[cost_ctr] ),
        FILTER (
            ALL('FactFINData'[DNum]),
            'FactFINData'[DNum] >= _startDNum &&
            'FactFINData'[DNum] <= _endDNum
        )
    )
       

2 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi LWJ2019 

       

      Glad that you have solved the issue. If possible, can you share your solution with the community so that other people who have similar issues in the future will benefit from it. Thank you!

       

      Best Regards,
      Jing