Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Calculating and grouping values from two identical column

Hi all,

Below is a sample table of my data and I would like to an overall table where it calculates overall number of wins, overall number of draws and overall number of losses for each team (note that the list in HomeTeam and AwayTeam are the same)

HomeTeamAwayTeamFTHGFTAGFTR
BurnleySwansea01A
Crystal PalaceWest Brom01A
EvertonTottenham11D
HullLeicester21H
Man CitySunderland21H
MiddlesbroughStoke11D
SouthamptonWatford11D
ArsenalLiverpool34A
BournemouthMan United13A
ChelseaWest Ham21H
Man UnitedSouthampton20H
BurnleyLiverpool20H
LeicesterArsenal00D
StokeMan City14A
SwanseaHull02A
TottenhamCrystal Palace10H
WatfordChelsea12A
West BromEverton12A
SunderlandMiddlesbrough12A
West HamBournemouth10H

What i have done

Picking the values separately from HomeTeam and AwayTeam is simple. What i am unable to do is to combine the records for HomeTeam and AwayTeam so that we have just 20 teams and the record will show for example:

Team | Played | W | D | L |

Burnley | 2 | 1 | 0 | 1 |

Swansea | 2 | 0 | 0 | 2 |

....

Any help is much appreciated!

Regards,
Wai Meng

12 Replies
vinieme12
Champion III
Champion III

I'd suggest a slight change as the total counts are coming incorrect , total matches played in the league should be 20 not 40.

GAME_FACT:

LOAD Rowno() as MatchID,

  HomeTeam,

    AwayTeam,

    FTHG,

    FTAG,

    FTR

FROM

[https://community.qlik.com/thread/264675]

(html, codepage is 1252, embedded labels, table is @1);

TeamsTab:

LOAD MatchID,

  HomeTeam as TEAM,

'Home' as GameFlag ,

  Pick(Match(FTR,'A','H','D'),'L','W','D') as MatchResult

resident GAME_FACT;

Concatenate

LOAD MatchID,

    AwayTeam as TEAM,

    'Away' as GameFlag,

      Pick(Match(FTR,'A','H','D'),'W','L','D') as MatchResult

resident GAME_FACT;

games_data.PNG

Check the app for expressions

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
vinieme12
Champion III
Champion III

the only difference is the way you count the Games Played, instead of count(TEAM) , you really need to be counting distinct games played which is why you need a MatchID.

But your choice!!

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Anonymous
Not applicable
Author

Thanks alot for this Vineeth!