Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago

Count Distinct Cumulative for Pareto

I have table like below:

YearMonthRegionProductItemValue
20251AsiaProduct AItem A1100
20251AsiaProduct AItem A2100
20251AsiaProduct AItem A3200
20251AsiaProduct BItem B1100
20251AsiaProduct BItem B2200
20251EuropeProduct AItem A1200
20251EuropeProduct AItem A2220
20251EuropeProduct AItem A3240
20251EuropeProduct AItem A4260
20251EuropeProduct AItem A5280
20251EuropeProduct BItem B3300
20251AmericaProduct BItem B1320
20251AmericaProduct BItem B4340
20251AmericaProduct BItem B3360


Which i want to count distinct items each region montly, and want to create pareto chart for viz. and i want to get table like below:

FilterMonth1  
     
RegionCount ItemTotal ItemPct**bleep**. Pct
Asia51435.71%36%
Europe61442.86%79%
America31421.43%100%


Can you help me with the dax for this case count distinct and cumulative sum

8 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Wasn't quite sure how you were wanting to define your SalesCount so it might need a tiny tweak. 
    I used:

    Sales Count = COUNTROWS(Sales)

    and:

    Pareto % = 
    IF(
        ISINSCOPE( Sales[Region]),
        VAR __AllSelectedReg = ALLSELECTED( Sales[Region] )
        VAR __RegTable = ADDCOLUMNS( __AllSelectedReg, "@Count", [Sales Count])
        VAR __CurrentCount = [Sales Count]
        VAR __CumSalesTable = FILTER(__RegTable, [@Count] >= __CurrentCount)
        VAR __CumSales = SUMX( __CumSalesTable, [@Count])
        VAR __AllSelectedSalesCount = CALCULATE( [Sales Count] , __AllSelectedReg)
        VAR __Result = DIVIDE(__CumSales, __AllSelectedSalesCount)
        RETURN
            __Result)

     

    and then a standard Line and Stacked Column Chart with Region on the X-axis and Pareto % on the Line y-axis

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Your dax quite good but still not solved, since the table that i showed before is masked. my dax to distinct count is like below :

      Count = CALCULATE(DISTINCTCOUNT(table1[item]),FILTER('table1','table1'[value] <> 0),FILTER('table1',NOT('table1'[market] = "abc" && 'table1'[Product] = "Product B")))

      so i got miss result like this
      Region Count Pareto
      Eropa 124 0.84
      Asia 18 0.96
      America 5 0.99
      Africa 3 1.01

      total pareto is over 100 percent and the calculation pct sligthly wrong.
      i think we should change this part, cuz my count using some kind of filters
       VAR __AllSelectedSalesCount = CALCULATE( [Sales Count] , __AllSelectedReg)
      • Anonymous's avatar
        Anonymous
        Not applicable

        is the issue not how you are using distinct count?

        the Distinct part is only checking for distinctness within the current row context (for example the current region) but when you are looking at a cumulative value there the context is across all regions.

         

        See below where I redfined salescount using distinctcount, particularly notice that the total for sales count is 10 despite the individual values when summed being higher than 10

         

  • Hi,

     

      Here is an alternate solution using certified, custom visual "Pareto by sio2Graphs".

     

    *make sure data does not include blanks when using below formula.
    Percent = FORMAT(DIVIDE(COUNT(Sheet1[Item]),COUNTROWS(ALLSELECTED('Sheet1')),1),"Percent")

     

    cynthia@sio2Graphs.com

    easy, effective, aesthetic

    try Pareto+ for advanced features

  • v-sathmakuri's avatar
    v-sathmakuri
    Community Support

    Hi Anonymous ,

     

    May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

     

    Thank you!!

  • v-sathmakuri's avatar
    v-sathmakuri
    Community Support

    Hi Anonymous ,

     

    I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If the responses has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

     

    Thank you!!

  • v-sathmakuri's avatar
    v-sathmakuri
    Community Support

    Hi Anonymous ,

     

    I hope the information provided is helpful. Feel free to reach out if you have any further questions or would like to discuss this in more detail. If responses provided answers your question, please accept it as a solution so other community members with similar problems can find a solution faster.

     

    Thank you!!