Forum Discussion

joshua1990's avatar
joshua1990
Icon for Post Prodigy rankPost Prodigy
5 years ago

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

  • 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;

     

    OrderSteps

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

     

    Regards,

    Hasham

      • HashamNiaz's avatar
        HashamNiaz
        Icon for Solution Sage rankSolution Sage

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