Solved Group by Year and Month - Crosstab Query (1 Viewer)

jack555

Member
Local time
Tomorrow, 01:39
Joined
Apr 20, 2020
Messages
93
Would like to compare the monthly figures against each year. Have a totals/crosstab query grouped at month level like below.

2020-01 25
2020-02 50
2020-03 40
2021-01 20
2021-02 25
2021-03 35

However, I would like to have this in the below format

Month20202021
12520
25025
34035

Tried crosstab with year and month in column and row heading but got as per screenshot. How can we do this in a better way

1616330327133.png
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:39
Joined
Oct 29, 2018
Messages
21,469
Hi. I created the following table.

1616337465301.png


And that resulted in this crosstab query.

1616337609121.png
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 17:39
Joined
Feb 19, 2002
Messages
43,266
You have to use a numeric month to sort by otherwise your year will start with april. You can sort by the number but show the text.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:39
Joined
Oct 29, 2018
Messages
21,469
You have to use a numeric month to sort by otherwise your year will start with april. You can sort by the number but show the text.
Oops, didn't see that. Thanks for the reminder. I guess I could try again when I get back in the office.

Cheers!

Sent from phone...
 

CJ_London

Super Moderator
Staff member
Local time
Today, 22:39
Joined
Feb 19, 2013
Messages
16,609
suspect the OP's crosstab is not correctly designed - perhaps there is another hidden grouped field as a row heading which is separating the years since the months are repeating
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:39
Joined
Oct 29, 2018
Messages
21,469
Oops, didn't see that. Thanks for the reminder. I guess I could try again when I get back in the office.

Cheers!

Sent from phone...
So, I adjusted the table like so.

1616372972357.png


And now, it comes out like this.

1616373002352.png
 

jack555

Member
Local time
Tomorrow, 01:39
Joined
Apr 20, 2020
Messages
93
suspect the OP's crosstab is not correctly designed - perhaps there is another hidden grouped field as a row heading which is separating the years since the months are repeating
Thank you. found the problem. using "yyyy-mm" format for sorting, this was the hidden field. Thanks for the clue. Now problem solved.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 14:39
Joined
Oct 29, 2018
Messages
21,469
Thank you. It worked for me. I tested creating a totals query and generating crosstab from the total query. your sample was an eye-opener for me.
Hi. Glad to hear you got it sorted out. Good luck with your project.
 

Users who are viewing this thread

Top Bottom