Forum Discussion

uif19085's avatar
uif19085
Helper III
3 years ago
Solved

Calculate Dynamic Ratios

Trying to find a way to change a ratio calculation with slicer which is having values from a column. 
For example: i have 3 values in a column: apples, pears, oranges and another column where i found which from these fruits are eaten or not, flaged with 1/0.
I want a slicer to select the fruit and get the ratio of that eaten fruit out of total. Total ratio of eaten apples is calculated like this: Total number of eaten apples / Total number of apples. From the slicer i want to change this calculation dynamically for each fruit. 
 

 

  • uif19085 ,

    try this in measure,

    Ratio of eaten fruit =
    VAR _eaten =
        CALCULATE ( COUNT ( Table[Fruits] ), Table[Flag] = 1 )
    VAR _all =
        CALCULATE ( COUNT ( Table[Fruits] ), ALL ( Table) )
    VAR _result =
        DIVIDE ( _eaten, _all )
    RETURN
        _result
    

    Thanks,

    Arul

7 Replies

  • Arul's avatar
    Arul
    Super User

    uif19085 ,

    try this in measure,

    Ratio of eaten fruit =
    VAR _eaten =
        CALCULATE ( COUNT ( Table[Fruits] ), Table[Flag] = 1 )
    VAR _all =
        CALCULATE ( COUNT ( Table[Fruits] ), ALL ( Table) )
    VAR _result =
        DIVIDE ( _eaten, _all )
    RETURN
        _result
    

    Thanks,

    Arul

  • Hello Arul , Thank you for your answer. Doesn't seem to work. The result should be 3.76% 

     

    • Arul's avatar
      Arul
      Super User

      uif19085 ,

      Can you show me the formula what you have use for measure?

      Thanks,

      Arul

      • uif19085's avatar
        uif19085
        Helper III

        Arul 
        Sure, but i have to show you the real data tables i use:

        Automated Ratio =
        VAR Auto = CALCULATE(COUNT(Artefact[Requirements Selection]), Artefact[Automated] = 1)
        VAR _all = CALCULATE(COUNT( Artefact[Requirements Selection]), ALL(Artefact))
        VAR _result = auto/_all
        RETURN
        _result
        I have a Slicer for Requirement Selection and I marked with 1 which from these are automated