Forum Discussion

ravanzaanen's avatar
ravanzaanen
Frequent Visitor
2 years ago
Solved

put value in column if record exist in other table with conditions in that table

Hi Guys,

figgering out powerbi and setting up a ranking system in an existing powerbi with tables we already got. the thing is i get gaps in my ranking because players did not participate on a matchtype so it jumps from 2 to 4 and skips 3 or it starts at 2 instead of 1

we gave people based on level an ranking and filtering in the powerbi. 

Solution get another column in ranking or actualy two where we filter on matchtypeid
I already added gender and leeftijd from players and check if the age is under or equal to 18 and put an X in.
I would like to do the same with matchtypeid for lets say singleplay and doubleplay to put an x in the column when found. 

So the names are not ideal sorry.

we have the tabel #"bond_jeugd_competitie_samen ranking"
with memberid in it 

memberidenkelrankingdubbelrankinggenderleeftijdjeugd
12340.20.5M20null
12350.41M18X
12360.52V17X
123712.6V33null

 

and tabel #"bond_jeugd_competitie_samen rankinglog" i won't bother you with all the **bleep** over there. just a few columns the rest isn't important.

memberidmatchtypeid
1234HE
1234HD
1236DE
1237DD
1237DD
1234HD
1236E

 

So the final table i'm looking for is 

memberidenkelrankingdubbelrankinggenderleeftijdjeugdsingleplaydoubleplay
12340.20.5M20nullXX
12350.41M18Xnullnull
12360.52V17XXnull
123712.6V33nullnullX

 

so in the end we can do something like this 

 

 

rankingdubbelspeljeugdopgeslacht = VAR CurVal = [dubbelranking]
RETURN
CALCULATE(
RANKX( 'bond_jeugd_competitie_samen ranking', [dubbelranking], CurVal, ASC, Dense ),
ALLEXCEPT( 'bond_jeugd_competitie_samen ranking','bond_jeugd_competitie_samen ranking'[gender],'bond_jeugd_competitie_samen ranking'[jeugd] )
)

 

 

 

 

and just add singleplay or doubleplay in the ALLEXCEPT 

But the satement to get the X in singleplay and doubleplay is breaking my head. 
we have 3 values for singleplay "E" "HE" and "DE" and 4 for doubleplay  "HD" "DD" "GD" and just "D"

There is an relation on memberid ranking 1 rankinglog many


Hope somebody can help

  • Hi ravanzaanen

     

    Power Query Solution:

     

    Result

     

    let
        Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUTLQMwKTpkDSF4iNDIBEXmlOjlKsDliRKVgapNQQqsTQAkhEwOTN4NpBBoWB5M2R5c2hOo30zKDyxsZwK2IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [memberid = _t, enkelranking = _t, dubbelranking = _t, gender = _t, leeftijd = _t, jeugd = _t]),
        Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUfJwVYrVQfBcYDwzIM8FLmcO4rlg52HqA2qLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [memberid = _t, matchtypeid = _t]),
        MergedQueries = Table.NestedJoin(Table1, {"memberid"}, Table2, {"memberid"}, "Table2", JoinKind.LeftOuter),
        Ad_SinglePlay = Table.AddColumn(MergedQueries, "singleplay", each if List.ContainsAny([Table2][matchtypeid], {"E", "HE", "DE"}) then "X" else null, type text),
        Ad_DoublePlay = Table.AddColumn(Ad_SinglePlay, "doubleplay", each if List.ContainsAny([Table2][matchtypeid], {"HD", "DD", "GD", "D"}) then "X" else null, type text),
        RemovedColumns = Table.RemoveColumns(Ad_DoublePlay,{"Table2"})
    in
        RemovedColumns

     

5 Replies

  • dufoq3's avatar
    dufoq3
    Icon for Community Champion rankCommunity Champion

    Hi ravanzaanen

     

    Power Query Solution:

     

    Result

     

    let
        Table1 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUTLQMwKTpkDSF4iNDIBEXmlOjlKsDliRKVgapNQQqsTQAkhEwOTN4NpBBoWB5M2R5c2hOo30zKDyxsZwK2IB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [memberid = _t, enkelranking = _t, dubbelranking = _t, gender = _t, leeftijd = _t, jeugd = _t]),
        Table2 = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUfJwVYrVQfBcYDwzIM8FLmcO4rlg52HqA2qLBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [memberid = _t, matchtypeid = _t]),
        MergedQueries = Table.NestedJoin(Table1, {"memberid"}, Table2, {"memberid"}, "Table2", JoinKind.LeftOuter),
        Ad_SinglePlay = Table.AddColumn(MergedQueries, "singleplay", each if List.ContainsAny([Table2][matchtypeid], {"E", "HE", "DE"}) then "X" else null, type text),
        Ad_DoublePlay = Table.AddColumn(Ad_SinglePlay, "doubleplay", each if List.ContainsAny([Table2][matchtypeid], {"HD", "DD", "GD", "D"}) then "X" else null, type text),
        RemovedColumns = Table.RemoveColumns(Ad_DoublePlay,{"Table2"})
    in
        RemovedColumns

     

    • ravanzaanen's avatar
      ravanzaanen
      Frequent Visitor

      Thanks for the help dufoq3  
      I only not see where you put the in list and if i change to my data somehow i get less X then expected
      It should be an or list so if it contains E or HE or DE then X else null for singleplay  But beside i put in the wrong forum i love to learn from this solution also. 😉   

       

      • dufoq3's avatar
        dufoq3
        Icon for Community Champion rankCommunity Champion

        Hi, as you can see it works with sample data. Provide new sample (data from your screenshot) and I can check.