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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors