Forum Discussion

tvw83's avatar
tvw83
New Member
5 years ago

Distinct Count rows based on Dimension Attribute Order Priority

Dear,

 

We have a particular business case where we have multiple documents and multiple status per document.

We would like to count the distinct number of documents per status but avoiding double counting (e.g. when a document having multiple status rows). There is no field like last creation date or last status, we can only detect the correct count based on the dimension  where we have an order of priority. See example below, I have added the dimension details...

E.g. DocumentId 1 has both a StatusID 1 and 2 , but based on the dimension table, we know that StatusID 2 has the highest priority (=the lower the number the higher the priority - but not so important) . Therefore when we count by status, the DocumentId should be counted with StatusID 2 only and not for StatusID 1.

 

Unfortunately, I'm quite new in Power BI and DAX and I could not find a function to derive this.

Anyone a suggestion ?

 

 

6 Replies

  • tvw83 , Few ways. Create a rank column and filter on 1.

    rank column = rankx(filter(Table, [document_id] = earlier([document_id])), [Status_id],,desc,dense)

     

    or try a measure like this.

    measure = calculate(count(Table[document_id]), filter(Table , Table[status]= calculate(max([Status_id]),allexcept(Table,table[document_id]))))

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi amitchandak,

      Unfortunately that is not completely what I'm looking for. I would like to sort/rank based on a field in the dimension table (dimPriority) that is not in the fact table. In my sample, I have put them in one table, but only StatusId is the key between both fact table and dimension.

       

      By coincidence, the result is the same if you sort on StatusID but that is not what I need.

      Question is thus, how do I sort/rank in the Fact Table (DocumentId, Date, StatusID) based on a field in the Dimension Table (dimPriority) ?

       

      Thank you in advance

      • mahoneypat's avatar
        mahoneypat
        Microsoft Employee

        To help suggest a specific expression, please provide an example of a visual (e.g., table or matrix) you would make that shows the correct result in context.

        Regards,

        Pat

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous 
    Because the filter expression is max([status id], if you want filter based on the priority. Try change the underlined part to min([Priority]), keeps others the same. 

     

     

     

    Paul Zheng _ Community Support Team
    If this post helps, please Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi,

      That's not fully correct.What I need is to get the minimum priority per documentId and as such I know the corresponding Status(Id).

      I tried to implement it :

       

      But the result is not correct:

      I become StatusID 3 = count of 4 (all documents)

      While the count result should be :

      StatusID 1 = 1 (DocumentId 2)

      StatusID 2 = 1 (DocumentId 1)

      StatusID 3 = 3 (DocumentId 3, 4,5)

      StatusId 4 = 0

       

      What is wrong with my measure ?