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
titanconsulting
Frequent Visitor

Generate table multiple columns

I'm struggling to deal with data that is coming in from an external API.  I'd like to do some analysis on College Football - but the data for the games in coming in with a home and an away team.  The front end is going to be driven by team - so I'll need a seperate record for each team so I can analyze no matter if they are home or away.

id                  school

2000Abilene Christian
2001Adams State
2003Adrian
2005Air Force
2006Akron
333Alabama
2010Alabama A&M
......

 

Year      id                 season week season_type home_id  home_team                  home_points  away_team      away_points

202240142653220221regular98Western Kentucky38Austin Peay27
202240140505920221regular77Northwestern31Nebraska28
202240143951220221regular125762Florida Memorial University39Edward Waters34
202240141321320221regular55Jacksonville State42Stephen F. Austin17
202240141325620221regular2439UNLV52Idaho State21
202240140414620221regular328Utah State31Connecticut20

 

So I'd like to see how many times Western Kentucky won reguardless if they are home or away.  Current thought is create a new table, combining a Years table, Season Base (week + season_type) and teams table to get a record for every game played by team.  Teams have bye weeks - so won't have a game each week.   Totally open to hearing this isn't the right approach though.  I think ideally this is a Power Query answer - but I'll deal with dax.

 

Here is my actual pbix file with the data in it

https://drive.google.com/file/d/15FeBnODGLPVy_RL_OX58ZhN4Nn4Tze9K/view?usp=sharing

 

Appreciate any help that can be given here.

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @titanconsulting ,

 

I think this is mostly a modelling quetion.

 

How about creating two relationships from your teams table ("teams dimension") to your results table ("results fact"). Then you could possibly create a measure with the following logic:

 

DIVIDE ( 

CALCULATE ( COUNT ( home_team ), home_points > away_points, USERELATIONSHIP ( id, home_team ) ) +

CALCULATE ( COUNT ( away_team  ), home_points < away_points, USERELATIONSHIP ( id, away_team ) ), 

CALCULATE ( COUNT ( home_team ), USERELATIONSHIP ( id, home_team ) ) +

 CALCULATE ( COUNT ( away_team ), USERELATIONSHIP ( id, away_team ) ) )

 

Note, the syntax might be wrong, but I hope this gives you an idea anyway.

 

Let me know if this helps and if not feel free to share your pbix file and I can have a look into it.

 

Thanks,

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @titanconsulting ,

 

I think this is mostly a modelling quetion.

 

How about creating two relationships from your teams table ("teams dimension") to your results table ("results fact"). Then you could possibly create a measure with the following logic:

 

DIVIDE ( 

CALCULATE ( COUNT ( home_team ), home_points > away_points, USERELATIONSHIP ( id, home_team ) ) +

CALCULATE ( COUNT ( away_team  ), home_points < away_points, USERELATIONSHIP ( id, away_team ) ), 

CALCULATE ( COUNT ( home_team ), USERELATIONSHIP ( id, home_team ) ) +

 CALCULATE ( COUNT ( away_team ), USERELATIONSHIP ( id, away_team ) ) )

 

Note, the syntax might be wrong, but I hope this gives you an idea anyway.

 

Let me know if this helps and if not feel free to share your pbix file and I can have a look into it.

 

Thanks,

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Accepting this as solution because it gave me some ideas to go forward with.  Don't know if my solution is the most efficient...but it works.  With the amount of data I've got, it'll work.

 

  1. Duplicated the games table - Labeled one as Home Game and the other as Away Game.
  2. Merged Team table to Home Game into new table.  Same for Away Game.
  3. Appended the two tables into a single table - Total Games.

It does work - this is my personal analysis so I not overly concerned about performance especially with the amount of data I've got.

 

Thanks for the help!

Greg_Deckler
Community Champion
Community Champion

@titanconsulting Maybe a combination of the two, you could start with this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZFNa4QwEIb/SvC8FBMTXY+ldKFfUljsHsRDqkMN2liSuEv/fWfcsgcV8vHmTeaZYVJVUbTbGvWuikQsBGoZcylSlYj/M8fp4GsatMv3qE/gAzjLXsCGqel/0UrIv598MJa9gyZLZEtmrGKVr5lZhroYXeguVzDx6L6AT6d9rwm2X8KSXPGNArlQWUreYRidaTV7g28UemClNWdw3oS53hyXx/aiXctOGpN6MuUyCU8EjlUSpVA/66b3oz2bYQB2DAihIHp5DPDTgWWHO3ZtCUWvuoFgla7ZQs61lcXrB26Kbp9a3Y23FIKv+iq53CAlgj6lDLq7xc5tfRithSaYZgqEi6O6/gM=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, id = _t, season = _t, season_type = _t, home_team = _t, home_points = _t, away_team = _t, away_points = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"id", Int64.Type}, {"season", Int64.Type}, {"season_type", type text}, {"home_team", type text}, {"home_points", Int64.Type}, {"away_team", type text}, {"away_points", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Year] = 2022)),
    #"Changed Type1" = Table.TransformColumnTypes(#"Filtered Rows",{{"id", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type1", {"Year", "id", "season", "season_type", "home_points", "away_points"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Value", "Team"}, {"Attribute", "HomeAway"}})
in
    #"Renamed Columns"

and then a DAX measure like this:

Wins = 
    VAR __Table = ADDCOLUMNS('Table',"PointDiff",[home_points] - [away_points])
    VAR __Table1 = 
        ADDCOLUMNS(
            __Table,
            "Win",
            SWITCH(TRUE(),
            [HomeAway] = "home_team" && [PointDiff] > 0,1,
            [HomeAway] = "away_team" && [PointDiff] < 0,1,
            0
            )
        )
RETURN
    SUMX(__Table1,[Win])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.