Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
michael_knight
Post Prodigy
Post Prodigy

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:

This is my main dataset where I'm able to see how much people are earning per monthThis is my main dataset where I'm able to see how much people are earning per month

 

 

This is a dataset which is used as an estimate on how much the employee should be earning over the period of timesThis is a dataset which is used as an estimate on how much the employee should be earning over the period of times

 

I want  to calculate the average of how much they've earnt and compare it to the estimate. I want to create a measure using DATESINPERIOD which will allow me to compare the Actual earning to the Estimated earning during a certain time frame

 

This is the measure I've got:

 

Sales Moving Annual Total -Year 1 = 
CALCULATE (
    [Total Earnings],
    DATESINPERIOD (
        OTE[StartDate],
        MAX ( OTE[Year1] ),
        -1,
        YEAR
    )
)

 

 

This is the results from the measures, as you can see it doesn't workThis is the results from the measures, as you can see it doesn't work

 

 

And this the relationships I'm usingAnd this the relationships I'm using

 

Any help will be much appreciated

 

PBIX: https://www.dropbox.com/s/ogqxkft7tb373xn/help%20-%20Copy%20%282%29.pbix?dl=0

 

Thanks,

Mike

1 ACCEPTED SOLUTION

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] )
)

image.png

 

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.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@michael_knight , You can add new column/s in second table. (based on what I got so far)

 

example

Sumx(filter(Table, Table [Date] >= OTE[StartDate] && Table[Date] <= OTE[Year1] ),Table[salary])

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak . That didn't work, do you have any other suggestions?

 

helpppp.PNG

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] )
)

image.png

 

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.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.