Date filter in query

Status
Not open for further replies.

Pettor

Board Regular
Joined
Aug 8, 2015
Messages
175
Hello guys,

I would like to create a query that will fill out the column "Goals Average" from a fixture table but I want this to be done only until the date that it is mentioned in the column "Date".
How could I do that?

Many thanks

DateLeagueTeamGoals Average
1/1/2020​
SpainBarcelona
2,5​
1/2/2020​
SpainBarcelona
2,4​
1/3/2020​
SpainBarcelona
2,3​
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I am not sure I follow. Can you provide more detail?

It might be helpful to show us what your data in your data Table looks like, and then based on that, show us what you want your Query to look like.
 
Upvote 0
Hi Joe,

The table with the fixtures is enormous and it will be difficult to be shared.
For simplicity sake let's say that it has all the matches and the goals scored and conceded.
I am running a query already to get the average goals per team but what I want is for every match to have the average of goals until the date of the match based on column A (Date).
Every time that a match is played the statistics are changing, so I want to have in the query the average of goals scored for the home team until the date of the match.
So instead of getting the data in table A, I receive the data like in table B where the query calculates the latest data and it fills out the column "goals average" with the same values for every line.

Is it more clear now?
A
DateLeagueTeamGoals Average
1/1/2020SpainBarcelona2,5
1/2/2020SpainBarcelona2,4
1/3/2020SpainBarcelona2,3


B
DateLeagueTeamGoals Average
1/1/2020SpainBarcelona2,3
1/2/2020SpainBarcelona2,3
1/3/2020SpainBarcelona2,3
 
Upvote 0
So, do you want the "Goals Average" to show the current average (all games played up to this point) for every single listing?
If so, what you want to do is an Aggregate (Totals) Query, where you group the records by the Team for every game played, and take the Average of the Goals.
So then you will have a query that has one record per team that has their current Goals Average.
Then create a new query that has your Dates/Teams data table, and join that to the query you just created, joining on "Team".
You can then return all the individual data fields from the data table, and the Average from the query.
 
Upvote 0
Thank you Joe, I will give it a try. Just a quick question because from my understanding (I am totally naive in databases) this method will return the result I already get, placing in every listing (row) the same current average of the same team, although I want to get the average of the team that is mentioned in column "team" but up to the date that is also mentioned in column "date". I may be totally wrong but if let's say, the data table has just 3 columns "date" (all the dates that there was a game, "team" (for simplicity let's have only two teams) and the "number of goals", how would you write it to get the average goals per team up to every date that is mentioned in tha date column? Many thanks
 
Upvote 0
Now that I am thinking it maybe I should create an average query grouping by date and team and then return to the new query the average that matches the date AND the team from the first aggregate query. I will give it a try and I will come back ?
Thanks!
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,214,649
Messages
6,120,730
Members
448,987
Latest member
marion_davis

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top