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

Is there an alternative for this conditional column solution?

Hi,

 

I am trying to answer an analysis question for the Online Chess Game dataset on https://www.mavenanalytics.io/data-playground

 

I am trying to answer the below query,

"What percentage of games are won by the player with the higher rating?"

 

The ratings are presented like below,

MHoque_0-1657122406091.png

 

I have been able to output the winners into a conditional column (higher/lower) via power query (transform data)  - I can then calculate the percentages with measures into something like this,

MHoque_1-1657123186877.png

This has worked for me however I am aware that this can impact performance as this increases the size of the overall file.

What would be the best practice in this instance? Is there a way to work around this with measures?

 

Thanks in advance for any assistance/advice,

Miz

 

1 ACCEPTED SOLUTION
AntonioM
Solution Sage
Solution Sage

You could write that as a measure, something like 

Higher % =
VAR higher =
    SUMX (
        Table,
        IF (
            ( Table[Winner] = "White"
                && Table[white_rating] > Table[black_rating] )
                || ( Table[Winner] = "Black"
                && Table[white_rating] < Table[black_rating] ),
            1
        )
    )
RETURN
    DIVIDE ( higher, [Total Games] )

and then format that as %

View solution in original post

5 REPLIES 5
AntonioM
Solution Sage
Solution Sage

You could write that as a measure, something like 

Higher % =
VAR higher =
    SUMX (
        Table,
        IF (
            ( Table[Winner] = "White"
                && Table[white_rating] > Table[black_rating] )
                || ( Table[Winner] = "Black"
                && Table[white_rating] < Table[black_rating] ),
            1
        )
    )
RETURN
    DIVIDE ( higher, [Total Games] )

and then format that as %

Thank you AntonioM - that worked 😊

 

A follow up query,

 

If I have the winner column (winner) and player rating columns (white_rating, black_rating) stored in separate dimension tables. How would I reference both tables working with a measure like the above?

 

Thanks again - I'll mark it as a solution!

You shoud be able to use RELATED and then sum over the fact table

 

SUMX (
        FactTable,
        IF (
            ( RELATED(DimTable1[Winner]) = "White"
                && RELATED(DimTable2[white_rating]) > RELATED(DimTable2[black_rating]) )
                || ( RELATED(DimTable1[Winner] = "Black"
                && RELATED(DimTable2[white_rating]) < RELATED(DimTable2[black_rating]) ),
            1
        )
    )

 

That worked thank you (just needed to add a closing bracket after "black").

 

I am still relatively new to Power BI/DAX but you have taught me quite a bit about using RELATED and IF - Thanks again!

Yes - I missed that one.

 

No worries!

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.