Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Get segment value when segment is used for calculations and not filtering

Hi,
I just begin with PowerBI and I would like to create a report where the user can select somes values from segments in order to sort the table, not filtering.
For example :

 

and when the user chooses :

 

So I have disabled the automatic filtering with the "Edit interactions" options in order to keep all the lines in my table but now, I am not able to calculate the segment value in my table. So I can't compare the segment value with the table value to calculate the score.


I get the segment value through this solution :
https://community.powerbi.com/t5/Desktop/How-to-get-filter-values-applied-to-a-label-displayed-in-Report/td-p/73235
but it doesn't work in my case.


How i can obtain the segment value in my table when i have disabled the filter ?


Thank you ?

  • Hi Anonymous 

     

    To achieve this you will need to create two dimensions, one for weapons and second for protection and a measure like below.

    Score = 
    VAR _weapon = CALCULATE( COUNTROWS( 'Table' ), ALL( 'Protection'[Protection] ) ) 
    VAR _protection = CALCULATE( COUNTROWS( 'Table' ), ALL( Weapon[Weapon] ) ) 
    RETURN _weapon  + _protection + 0
    I have attached a file with a model for reference
     
    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski

     

     

     

4 Replies

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

    Hi Anonymous 

     

    To achieve this you will need to create two dimensions, one for weapons and second for protection and a measure like below.

    Score = 
    VAR _weapon = CALCULATE( COUNTROWS( 'Table' ), ALL( 'Protection'[Protection] ) ) 
    VAR _protection = CALCULATE( COUNTROWS( 'Table' ), ALL( Weapon[Weapon] ) ) 
    RETURN _weapon  + _protection + 0
    I have attached a file with a model for reference
     
    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      OK, if i calculate the selectedvalue with this formula, I can do the comparaison :

      SelectedValueProtection = CALCULATE(SELECTEDVALUE(data[Protection]);ALL( Weapon[Weapon] ))

       

      Thank you for your help
      • Mariusz's avatar
        Mariusz
        Icon for Community Champion rankCommunity Champion

        Hi Anonymous 

        Sorry, for the late reply, please see the attached solution.

        I've split the original score measure into two to achieve this.

        Score Protection = CALCULATE( COUNTROWS( 'Table' ), ALL( Weapon[Weapon] ) ) 
        Score Weapon = CALCULATE( COUNTROWS( 'Table' ), ALL( 'Protection'[Protection] ) ) 
        Score = [Score Weapon]  + [Score Protection] + 0

        Please see the attached file for reference.

         

        Your solution is equally as good, so you might stick to it! 

         

        Best Regards,
        Mariusz

        If this post helps, then please consider Accepting it as the solution.

        Please feel free to connect with me.
        Mariusz Repczynski

         

         

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for the tip, it works perfectly !!!


      But now, i have another problem.
      I would like to change the font color if the table value matches with the segment value.

      So, i would like to compare these 2 values.

      But the SelectedValue(table[Weapon]) or the SelectedValue(table[Protection]) is not empty only for the line matches with 2 choices, so the comparaison fails :

       

      How can I do ?

       

      Best Regards,