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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Add column based off another column category - formaula help needed

Hi guys,

 

I have the following sports table that im hoping to add a couple of columns to. i have the information in the black, but i would like to add the information in the red

 

 

Club         |    Opposition     |     Points scored     |    Points conceded     |     Points difference 

Team A          Team B                     20                                 30                                   -10

Team B          Team A                     30                                20                                    10

 

 

Any help would be much appreciated!

Thanks!

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi js1289, 

If you want to compare value between each Club, i think you could fun join table like below

let
    Source = Table.NestedJoin(T4, {"Round"}, T4, {"Round"}, "T4", JoinKind.FullOuter),
    #"Expanded T4" = Table.ExpandTableColumn(Source, "T4", {"Round", "Club", "Points Scored"}, {"Round.1", "Club.1", "Points Scored.1"})
in
    #"Expanded T4"

RoundClubPoints Scored

1 A 20
1 B 30
1 C 10
1 D 15
2 A 35
2 B 30
2 C 25
2 D 20

Then you will get result like below

531.PNG

 You could remove column and modify your table to see whether it work or not.

Best Regards,
Zoe Zhi

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

9 REPLIES 9
Anonymous
Not applicable

Thank you very much everyone!!

AiolosZhao
Memorable Member
Memorable Member

After I saw @az38 's answer, the LOOKUPVALUE is a better way to solve it, the measure can be:

 

Meausre = LOOKUPVALUE('Table'[POINT],'Table'[OPPOSITION],MAX('Table'[CLUB]),'Table'[ID],MAX('Table'[ID]),"NO VALUE")

 

Aiolos Zhao 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




az38
Community Champion
Community Champion

@AiolosZhao 

i think calculated column will work a little bit faster then and will need in less memory consumption. but Im not sure 🙂

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
AiolosZhao
Memorable Member
Memorable Member

Hi @Anonymous ,

 

I think you must have an ID or a key to distinguish every game.

 

So I made up below sample data:

IDCLUBOPPOSITIONPOINT
1AB20
1BA30
2AB10
2BA50

 

My measure :

 

Measure = CALCULATE(SUM('Table'[POINT]),ALLEXCEPT('Table','Table'[ID])) - SUM('Table'[POINT])
Measure 2 = SUM('Table'[POINT]) - (CALCULATE(SUM('Table'[POINT]),ALLEXCEPT('Table','Table'[ID])) - SUM('Table'[POINT]))

 

 

And result:

Add column based off another column category - formaula help needed.PNG

 

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




az38
Community Champion
Community Champion

Hi @Anonymous 

try 2 columns

Points conceded = lookupvalue(Table1[Points scored];Table1[Club];[Opposition])
Points Difference = [Points scored]-[Points conceded]

It should be enough, but I've got a lot of experience in the sports stats analysis and i could advice you to use matchday_id or match_id index column for long-term competitions

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Thanks for your help guys @az38 and @AiolosZhao ! I tried this and it worked perfectly although I do now realise I will have multiple games for different rounds and teams....so the table will end up

 

 

RoundClubOppositionPoints ScoredPoints ConcededPoints difference
1AB

20

30-10
1BA302010
1CD1015-5
1DC15105

2

AC352510
2BD302010
2CA2535-10
2DB2030-10

 

Still trying to populate the two columns in red so Im guessing its a similar formula with extra factors taking such as club and round?

 

Thanks again!

dax
Community Support
Community Support

Hi js1289, 

If you want to compare value between each Club, i think you could fun join table like below

let
    Source = Table.NestedJoin(T4, {"Round"}, T4, {"Round"}, "T4", JoinKind.FullOuter),
    #"Expanded T4" = Table.ExpandTableColumn(Source, "T4", {"Round", "Club", "Points Scored"}, {"Round.1", "Club.1", "Points Scored.1"})
in
    #"Expanded T4"

RoundClubPoints Scored

1 A 20
1 B 30
1 C 10
1 D 15
2 A 35
2 B 30
2 C 25
2 D 20

Then you will get result like below

531.PNG

 You could remove column and modify your table to see whether it work or not.

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi @Anonymous ,

 

I think you can use my measure above your reply, I think that's what you want, if you want to create two calculated columns, I think the expression should be:

Points Conceded = LOOKUPVALUE('Table'[Points  Sored],'Table'[Opposition],MAX('Table'[Club]),'Table'[Round],MAX('Table'[Round]),"NO VALUE")
Points difference = [Points Scored] - [Points Conceded]

  Please try.

Aiolos Zhao





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




az38
Community Champion
Community Champion

@Anonymous 

highly reccomend to create a column match_id (unique for each couple of rows) - you could easily find a red columns by this key

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.