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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

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]))))

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
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
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.