Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Stacked bar chart help to use multiple values

I've 3 tables 

Table - GroupData (GroupName, MaxCount)

            WorkData(GroupName, HostName, CategoryName, Count, Date)

            Calendar(Date, Year)

 

GroupData and WorkData are mapped 1-Many and Calendar-GroupData is 1-Many

 

On the stacked bar chart, i want to display the Group Max count along with counts for each category in the group and legend. I am unable to use multiple values along with legend i.e., use GroupData (MaxCount) and WorkData(Count) for every category (legend)

GroupData

ParentGroupGroupNameMaxCount
1A100
1B200
2C150
3D75

 

 

WorkData

DateGroupNameCategoryHostCount
03-18-2020AA1Host110
03-18-2020AA2Host270
03-18-2020AA1Host35
03-19-2020AA2Host120
03-20-2020BA1Host1015
03-20-2020BA2Host1120
03-18-2020CA2Host1415
03-19-2020CA1Host1425

 

please help. TIA

 

 

 

  • Hi,

     

    Please try to create this table first:

    Table = UNION(DISTINCT('WorkData'[Category]),{{"MaxCount"}})

    Then try this measure:

    Measure = SWITCH(SELECTEDVALUE('Table'[Category]),"MaxCount",MAX('GroupData'[MaxCount]),CALCULATE(SUM(WorkData[Count]),FILTER('WorkData','WorkData'[Category] in DISTINCT('Table'[Category]))))

    The result shows:

    Here is my changed pbix file:

    pbix 

     

    Best Regards,

    Giotto Zhi

7 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your quick reply but I do not understand how that would fit into my issue

       

      It seems, if i can group by, pivot the WorkData table by category and merge the data by groupName to extract MaxCount, i would be able to easily plot the graph. I tested this in Excel but still cannot figure out how to acheive the same in power bi

       

       

  • v-gizhi-msft's avatar
    v-gizhi-msft
    Community Support

    Hi,

     

    According to your description, i choose GroupData and WorkData tables to test without calendar table.

    Then try to create a calculated column first:

    Group&Category = WorkData[GroupName]&"-"&WorkData[Category]

    Try this measure:

    Max Count = CALCULATE(SUM(GroupData[MaxCount]),FILTER(WorkData,WorkData[GroupName] in FILTERS(GroupData[GroupName])))

    Choose the above column,measure and [Count] as a stacked bar chart, it shows:

    Here is my test pbix file:

    pbix 

    Hope this helps.

     

    Best Regards,

    Giotto Zhi

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for you help but requirement has changed and this isn't needed any more. The output i was looking for is as below. Also, legend needs to show the category names

       
      • Anonymous's avatar
        Anonymous
        Not applicable