Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
tvw83
New Member

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...

tvw83_0-1605813650804.png

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 6
V-pazhen-msft
Community Support
Community Support

@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. 

 

max to min.JPG

 

 

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
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 :

timvw_0-1606395408984.png

 

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 ?

 

amitchandak
Super User
Super User

@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
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

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





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi, I slightly changed the data to show a real case.

Below printscreen of the relationship. I would like to count based on the field Priority in the dimension table.RelationshipRelationship

And hereafter a printscreen of the Fact, Dimension tables as matrix.

Please look at DocumentId 5, it should be counted once for StatusID=3 and not StatusID 4. Why ? Based on the priority (the lower the more important), StatusID 3 is prior. So I would like to count it for that status.

But for this, I need to be able to sort based on the Priority column.

 

Matrix of Fact, Dimension and resultMatrix of Fact, Dimension and result

 

Any suggestion ?

Kr

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.