Forum Discussion

michael_knight's avatar
michael_knight
Icon for Post Prodigy rankPost Prodigy
5 years ago
Solved

DATESINPERIOD with different tables

Hi,   I'm trying to calculate the average income using dates from a seperate table and the DATESINPERIOD table   These are the tables I've got:       I want  to calculate the aver...
  • v-kkf-msft's avatar
    v-kkf-msft
    5 years ago

    Hi michael_knight ,

     

    Please try the following measures:

     

    Rolling average -Year1 = 
    VAR __DATE_PERIOD =
    DATESINPERIOD (
        'Date'[Full Date],
        MAX(OTE[Year1]) ,
        -1,
        YEAR
    )
    RETURN
    	AVERAGEX(
    		CALCULATETABLE( Earnings, __DATE_PERIOD ),
    		'Earnings'[Salary] + Earnings[Commission]
    	)
    Total Rolling average -Year1 = 
    IF(
        ISFILTERED(Agents[Agent]),
        [Rolling average -Year1],
        AVERAGEX( ALLSELECTED(Agents[Agent]), [Rolling average -Year1] )
    )
    Rolling average -Year2 = 
    VAR __DATE_PERIOD =
    DATESINPERIOD (
        'Date'[Full Date],
        MAX(OTE[Year2]) ,
        -1,
        YEAR
    )
    RETURN
    	AVERAGEX(
    		CALCULATETABLE( Earnings, __DATE_PERIOD ),
    		'Earnings'[Salary] + Earnings[Commission]
    	)
    Total Rolling average -Year2 = 
    IF(
        ISFILTERED(Agents[Agent]),
        [Rolling average -Year2],
        AVERAGEX( ALLSELECTED(Agents[Agent]), [Rolling average -Year2] )
    )
    Rolling average -Year3 = 
    VAR __DATE_PERIOD =
    DATESINPERIOD (
        'Date'[Full Date],
        MAX(OTE[Year3]) ,
        -1,
        YEAR
    )
    RETURN
    	AVERAGEX(
    		CALCULATETABLE( Earnings, __DATE_PERIOD ),
    		'Earnings'[Salary] + Earnings[Commission]
    	)
    Total Rolling average -Year3 = 
    IF(
        ISFILTERED(Agents[Agent]),
        [Rolling average -Year3],
        AVERAGEX( ALLSELECTED(Agents[Agent]), [Rolling average -Year3] )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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