Forum Discussion

324's avatar
324
Helper I
3 years ago

Adding a Count Distinct Quick Calculation to Bar Chart

I've created a bar chart with a level-of-detail calculation as shown below. However, instead of individual codes along the bottom, I want counts of how many times codes are used. The x-axis would be 1, 2, 3, 4, ... and the height of the bars would represent how many codes were used 1, 2, 3, 4, ... times. I don't see a Count Distinct quick calculation in Power BI to accomplish this for this chart. How would I go about this? Thank you!

 

 

5 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    324 Depends on the data but generally either DISTINCTCOUNT or COUNTROWS(DISTINCT(...))

    Sorry, having trouble following, can you post sample data as text and expected output?
    Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

    • 324's avatar
      324
      Helper I

      Greg_Deckler Here is some more information:

      I have a Tableau histogram I want to replicate in Power BI showing project number groupings. Projects receive a new project number each fiscal year, but there is an identifier column that groups these projects together. For example, a continuing project in 2019, 2020, and 2021 could have three distinct project numbers, but are grouped together by one indicator value.

       

      I used this calculation in Tableau: 

      {FIXED [Project Identifier]:COUNTD([MITRE Project Number])}

       

      I converted the above in Power BI with the following: 

      LOD = CALCULATE(DISTINCTCOUNT('Appended Data'[EPI]), ALL('Appended Data'[Project Number]))

       

      Now, I'm just trying to get my histogram to look like a true histogram instead of one project for every bar.

       

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        324 So, probably want a disconnected table for the values you want in your x-axis. Then you would construct your measure to return the DISTINCTCOUNT filtered for that value. Sorry, I'm still not certain what those 1, 2, 3, ,4 and 5 represent.