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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
joshua1990
Post Prodigy
Post Prodigy

Count last entry per order

Hey guys!

I need to count the last entry per order.

I have an Order Header:

Order-Nr (Key)Date
101.01.2021
201.01.2021

 

Then I have an Order Master

Order-Nr (Key)Step (Key)Date
10101.01.2021
10205.01.2021
10307.01.2021

 

And I have a Step Description Table:

Step (Key)Descr
01XX
02BB

 

What I need now is a Matrix like this:

Order-Nr010203
1  1
21  

 

So this matrix will show me the last/ current step for each order.

 

How would you build a measure to get this result?

3 REPLIES 3
HashamNiaz
Solution Sage
Solution Sage

Hi !

You can use following DAX to get the desired output;

LatestStep = 
    VAR _LastOrder = MAX(OrderStep[Step])
    VAR _LatestOrder = CALCULATE(_LastOrder, ALLSELECTED(Steps[Step]))
RETURN
    IF([LatestOrder] = [LastOrder], 1, BLANK())


Here is a sample Data Model diagram;

 

OrderStepsOrderSteps

In your matrix visual on column headers, [Step] choose show items with no data.

 

Regards,

Hasham

@HashamNiaz Thanks a lot! Is max also working for strings?

You can treat Step No as Numeric, so MAX() will be robust. MAX() still works with strings but will not gurantee expected results.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors