Forum Discussion

FabioF's avatar
FabioF
Frequent Visitor
2 years ago
Solved

Problem creating an aggregation based on a measure

Hi everyone, I'm struggling with the issue in the subject of this message. I'll try to explain the scenario as best as I can, I apologize in advantage for my bad english. I have a table (let's na...
  • Daniel29195's avatar
    2 years ago

    FabioF 

     

    from my understanding, and please correct me if im wrong, 

    if exmaple, you have 4 categories as premium --> 4 /  total nb of categories 

    ( all of this is affected by your slicers ) 

     

    this is your measure : 

    PREMIUM_CATEGORY = CALCULATE(IF(DISTINCTCOUNT('TBL'[ID])>=3,1,0))

     

     

    %  measure = 

    var prem_category  =

    filter(
          addcolumns(

                   allselected(tbl[category_column]),

                      "@c" ,  [PREMIUM_CATEGORY]

           ),

           [@c] = 1 
    )

     

     

    var total_categories = allselected(tbl[category_column])

     

     

    return 

    divide( countrows(prem_category ) ,  total_categories , 0 )

     

     

     

    If my response has successfully addressed your issue kindly consider marking it as the accepted solution! This will help others find it quickly. Dont forget to hit that  thumbs up button 🫡👍

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi FabioF 

     

    For your question, here is the method I provided:

     

    Here's some dummy data

     

    "TBL"

     

    Create a measure to calculate the quantity of each type and make a judgment.

    PREMIUM_CATEGORY = 
        var category = 
            CALCULATE(
                COUNTROWS('TBL'), 
                FILTER(
                    ALLSELECTED('TBL'), 
                    'TBL'[CATEGORY] = MAX('TBL'[CATEGORY])
                )
            )
    RETURN IF(category >= 3, 1, 0)

                    

     

    Create a measure to calculate percentage.

    Measure = 
    VAR TOTAL = 
        CALCULATE(
            DISTINCTCOUNT('TBL'[CATEGORY])
        )
    VAR TOTAL_PRE = 
        CALCULATE(
            DISTINCTCOUNT('TBL'[CATEGORY]), 
            FILTER(
                ALLSELECTED('TBL'), 
                'TBL'[PREMIUM_CATEGORY] = 1
            )
        )
    RETURN DIVIDE(TOTAL_PRE, TOTAL)

     

    Here is the result.

     

     

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

     

  • FabioF's avatar
    2 years ago

    Hi guys, first of all thank you very much for your answers. In the meantime I figured out a way to solve the issue.
    As soon as possible I will reply and test also your suggestions and also add the details of mine!
    Thanks so much again, I'll keep in touch!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi FabioF 

     

    If my answer is correct, please mark it as accept as solution.

     

    Regards,

    Nono Chen

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.