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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
montilla
Regular Visitor

Distinct count considering last date

Hello friends!
I have the following product sales facts table:

OrderProductDelivery DatecStatus
1Mouse2019-12-01Delayed Delivery
1Keyboard2020-01-01Delayed Delivery
2CPU2019-12-20Delayed Delivery

 

Using a count measure distinct by order number, I get the total orders delivered. In this example, the measure would return the total of 02 orders.

However, by plotting this measure on an axis line chart by date, the chart shows in the period the total of 03 orders delivered using the same previous measure because 1 order has deliveries on different dates.

I would like some help from you to know how to change this so that it shows in the graph the total of 02 orders, taking the largest date in the order that contains more than 01 delivery with different dates.

Can you help me?

Appreciate!

 

Below, the measure used:

mDelivered Orders = CALCULATE(DISTINCTCOUNT(FollowUp[Order]);USERELATIONSHIP(Calendar[Date];FollowUp[Delivery Date]);FollowUp[cStatus]="Delayed Delivery")
4 REPLIES 4
Anonymous
Not applicable

@montilla Here is my approach.

First create a calculated column to get the max date per order.

Column = CALCULATE(MAX('FollowUp'[Delivery Date]),ALLEXCEPT('FollowUp','FollowUp'[Order]))

Modify your measure. i.e. use new column in relationship instead of delivery dates.

Measure = CALCULATE(DISTINCTCOUNT(FollowUp[Order]),USERELATIONSHIP('Calendar'[Date],FollowUp[Column]),FollowUp[cStatus]="Delayed Delivery")

 If it helps accept as solution.

Good morning everyone!

Dear @Anonymous , your answer solved my problem. Thank you for your attention and support!
If you are not ordering too much, I would like to post a status column comparing whether within each order all items have a delivery date. If EVERYONE owns, throw in this column the value "Done". If there is at least 01 blank date, throw the value "Open". The column would only have the possibility of these 02 values.
Since I'm new to DAX, I still don't know how to get an array from an order's product list and compare if any date is blank. I have no idea how to do this considering order by order.

Could you help me with this problem?
Thanks again!

Anonymous
Not applicable

@montilla There are ways to do it. Here is the one approach

Column = 
VAR _order = CALCULATE(COUNT('Table'[Order]),ALLEXCEPT('Table','Table'[Order]))
VAR _date = CALCULATE(COUNT('Table'[Delivery Date]),ALLEXCEPT('Table','Table'[Order]))
RETURN IF((_order-_date)>0,"Open","Done")
montilla
Regular Visitor

Up! Someone?

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.