Forum Discussion

tmhalila's avatar
tmhalila
Resolver II
4 years ago
Solved

Creating a measure for category

Hello,

I have a dataset with two tables, one for the age group and the other for services completed. I want to create a visual by category of the age group for those who completed one service, two services, and more like in the chart below. I was thinking about the Count and switch function but have failed to go about it. Please assist

 

Service dataset attached: ServiceTable 

Expected chart

 

Age group table

agegroupidname
5B9FE2ED-10B6-4295-A13A-055021CA87D120-24
CD3E266B-02E7-4069-A01F-84A6C447829425-29
99A6E90F-36FB-4C67-8214-AC3AFF33176815-19
678F724B-A612-4D3F-962D-B95112CD1CFD10-14
  • TheoC's avatar
    TheoC
    4 years ago

    Hi tmhalila 

     

    Haha - alright, that sounds good.  You can use the following to create a calculated column:

     

    _colDistinctClientServices = 

    CALCULATE
    DISTINCTCOUNT ( Services[serviceid] ) , 
    ALLEXCEPT ( 'Services' , Services[clientid] ) , Services[_CompletedServices] = "Completed"
    )

     

    Once you have added the column, you can then drag it onto the visual as the "Legend".  This will give you the following:

     

    Power BI file attached 🙂

     

    Theo 

7 Replies

  • TheoC's avatar
    TheoC
    Community Champion

    Hi tmhalila 

     

    I've put together the attached PBIX which hopefully will assist.  I recreated your model with an "Age Group" table just to make sure there are similarities (grouped by AgeGroupID).  Output as per below:

     

    I basically did two things:

     

    1. Measure for Distinct Count on Completed Services given the way in which this was created / calculated is unknown but did have unique figures:
      _distinctcount = DISTINCTCOUNT ( 'Services'[CompletedService] ) 
    2. Calculated column using:
      _CompletedServices = CALCULATE ( [_distinctcount] , ALLEXCEPT ( 'Services' , 'Services'[ClientID] ) )

    From here, I just dragged the various fields into the respective visual.

     

    Hoping it's what you're after.

     

    Thanks heaps,

     

    Theo

    • tmhalila's avatar
      tmhalila
      Resolver II

      Thanks for the quick feedback, this one provides different results.

      The Column CompletedService gives us the status of clients who completed services, those with 1 completed and those with 0 not completed.

       

      Hence, we expect to have clients who completed multiple services, those who completed one, and others who completed zero. From the serviceID we have different types of IDs meaning different services of which some clients completed many while others complete none.

       

      Sorry, I think I missed explaining clearly in the first post.

      • TheoC's avatar
        TheoC
        Community Champion

        Hi tmhalila 

         

        I definitely didn't get that from your post haha.  See attached PBIX.  All you need to do is change the calculated column to the following:

         

        _CompletedServices = SWITCH ( TRUE () , Services[CompletedService] = 1 , "Completed" , "Not Completed" )

         

        Hope that helps 🙂

         

        Theo