Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dynamic pareto table

I hope that you are in for a treat... a brain squeezing treat! 

I want to make a pareto curve that can adjust itself based on selected Country. 

I have the following data:

CountryCompany MembersUnits
V-CH14425320104
V-DK1374353094
V-DK1264918085
V-D1003821174
V-F1022837769
V-I94845164
V-DK1418902163
V-CH1044010161
V-DK1268125961
V-D1006897654
V-CH1330389050
V-CH1042940845
V-DK1264472843
V-D1004496742
V-I94846542
V-D1003902139
V-CH1043332238
V-DK1327311136
V-DK1264917936
V-A1044656036
V-I94852136


I would like to visualize a table that shows: 1) Rank, 2) Cumulative Total, and 3) Cumulative Total %.

CountryCompany MembersUnitsRankCumulativeCumulative %
V-CH1442532010411041,0%
V-DK137435309421982,0%
V-DK126491808532832,8%
V-D100382117443573,6%
V-F102283776954264,2%
V-I9484516464904,9%
V-DK141890216375535,5%
V-CH104401016186146,1%
V-DK126812596196756,7%
V-D1006897654107297,3%
V-CH1330389050117797,8%
V-CH1042940845128248,2%
V-DK1264472843138678,6%
V-D1004496742149099,1%
V-I94846542159519,5%
V-D1003902139169909,9%
V-CH104333223817102810,2%
V-DK132731113618106410,6%
V-DK126491793619110011,0%
V-A104465603620113611,3%
V-I9485213621117211,7%


In addition, users wish to have the ability to filter on country e.g. If they filter on "V-DK" (Denmark), they wish to have the following result:

CountryCompany MembersUnitsRankTotalCumulativeCumulative %
V-DK137435309411108948,5%
V-DK12649180852110817916,2%
V-DK14189021633110824221,8%
V-DK12681259614110830327,3%
V-DK12644728435110834631,2%
V-DK13273111366110838234,5%
V-DK12649179367110841837,7%



Can anyone help me on how to acheive this in PowerBI? 🙂 

Kind Regards
Martin

  • lbendlin's avatar
    lbendlin
    4 years ago

    Add a small random number to your values to break the ties.

  • Great solution lbendlin ! Hadn't thought of that!

    Ok so following this great idea, create the following:

    Add a new column to the fact  table with the following:

    and then:

    Unit temp = [Sum Units] +  SUM(FactTable[Random])
    RNK Temp = RANKX(ALLSELECTED(FactTable), [Unit temp],,DESC,Dense)
    Cumulative =
    VAR RNK = [RNK Temp]
    RETURN
        IF (
            ISBLANK ( [Sum Units] ),
            BLANK (),
            IF (
                ISINSCOPE ( 'Dim Country'[DCountry] ),
                CALCULATE (
                    [Unit temp],
                    FILTER ( ALLSELECTED ( FactTable ), [RNK Temp] <= RNK )
                )
            )
        )
    
    % Cumul = 
    VAR _Total = CALCULATE([Unit temp], ALLSELECTED(FactTable))
    RETURN
    DIVIDE([Cumulative], _Total)

    You can decide what to display in the visual. I've kept the original [Sum Units] and [Rank] measures.

     

     

     

     

8 Replies

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    Great solution lbendlin ! Hadn't thought of that!

    Ok so following this great idea, create the following:

    Add a new column to the fact  table with the following:

    and then:

    Unit temp = [Sum Units] +  SUM(FactTable[Random])
    RNK Temp = RANKX(ALLSELECTED(FactTable), [Unit temp],,DESC,Dense)
    Cumulative =
    VAR RNK = [RNK Temp]
    RETURN
        IF (
            ISBLANK ( [Sum Units] ),
            BLANK (),
            IF (
                ISINSCOPE ( 'Dim Country'[DCountry] ),
                CALCULATE (
                    [Unit temp],
                    FILTER ( ALLSELECTED ( FactTable ), [RNK Temp] <= RNK )
                )
            )
        )
    
    % Cumul = 
    VAR _Total = CALCULATE([Unit temp], ALLSELECTED(FactTable))
    RETURN
    DIVIDE([Cumulative], _Total)

    You can decide what to display in the visual. I've kept the original [Sum Units] and [Rank] measures.

     

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you so much for your help PaulDBrown, and not at least lbendlin

      I am sending you a welldeserved highfive from Denmark

       

      Kind regards
      Martin

  • Anonymous I don't understand your Cumulative Total % column examples - shouldn't they end up at 100% for each last row?

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi lbendlin , 

       

      you are totalt right and sorry for the confusion. I thought I could add the Excel calculation as documentation, but was instead forced to copy a part of it. 

      nevertheles, do you know how it can be solved? 😃

  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    With this model:

    and the following measures:

    Sum Units = SUM(FactTable[Units])
    Rank =
    IF (
        ISBLANK ( [Sum Units] ),
        BLANK (),
        IF (
            ISINSCOPE ( 'Dim Country'[DCountry] ),
            RANKX ( ALLSELECTED ( FactTable ), [Sum Units],, DESC, DENSE )
        )
    )
    

     

    Cumulative =
    VAR RNK = [Rank]
    RETURN
        CALCULATE ( [Sum Units], FILTER ( ALLSELECTED ( FactTable ), [Rank] <= RNK ) )
    
    % Cumul =
    VAR _Total =
        CALCULATE ( [Sum Units], ALLSELECTED ( FactTable ) )
    RETURN
        DIVIDE ( [Cumulative], _Total )
    

     

    You will get:

     

    I've attached the sample PBIX file

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi PaulDBrown 

      Thank you so much for your feedback! Your solution is very close to what I need 😄 

      I notice that your "Rank", "Cumulative total" and "Cumulative %" does not count values that aren't unique. E.g. when filtering on Denmark, there are 2 "company members" that have sold 36 units, and your rank subsequently provides them with the same value, which also affects your "cumulative total" and "Cumulative %"

      Do you have an easy fix for this issue? 😄

      Kind regards
      Martin

      • lbendlin's avatar
        lbendlin
        Super User

        Add a small random number to your values to break the ties.