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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
Power-CJ
Helper I
Helper I

DAX Calculated Column for Last Delivery Date

Hello, 

 

I'm sure, that the solution is very simple, but i'm not getting in better mode for a while:

 

Sell-to-CustomerShipment DayLast Shipment Day
5255513.01.2023 
5255503.02.202313.01.2023
5255503.02.202313.01.2023
5255508.02.202303.02.2023
5255510.02.202308.02.2023
5255517.02.202310.02.2023
5255522.02.202317.02.2023

 

Here is my Table with the calculated Column Last Shipment Day. Because of 2 Orders at 03.02 there are double Values in my Calculated Column. This i want to avoid, because based on the LastDeliveryDate i'm calculating the Duration between Orders.

 

How i can proofe in my Dax Code if there have been calculatet the same date-value before.

 

Here is my Dax-Code of the Calculated Column Last Shipment Day:

 

Last Shipment Day =
CALCULATE(
    MAX('Order'[Shipment Date]),
    FILTER(
        'Order',
        'Order'[Sell-to Customer No_] = EARLIER('Order'[Sell-to Customer No_])
        && 'Order'[Shipment Date] < EARLIER('Order'[Shipment Date])
    )
)
6 REPLIES 6
Power-CJ
Helper I
Helper I

Hello,

thanks for the response. But this solution doesnt fit the requirement.

In My Case the third line of Last ShipmentDay should be blank because the value 01/13/23 appears in the column before. If there will be a identical value in the column it should show blank.

 

Based on this column i'm plannung to calculte an additional Column with the duration between delivery. If there wont be a blank, it will calculate this duration double times.

 

I hope with this detail information u habe a better imagine of my issue.

 

Thanks a Lot

 

Power-CJ

Anonymous
Not applicable

Hi @Power-CJ ,

Have a try.

Column = 
VAR _customer = 'Table'[Sell-to-Customer]
VAR _index = 'Table'[Index]
VAR _date_1 =
    CALCULATE (
        MIN ( 'Table'[Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = _customer
                && 'Table'[Index] = _index - 1
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'Table'[Last Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
                && 'Table'[Shipment Day] = EARLIER ( 'Table'[Shipment Day] )
        )
    )
VAR _index_doub =
    MAXX ( 
        FILTER ( 
            ALL('Table'),
            'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
                && 'Table'[Shipment Day] = EARLIER ( 'Table'[Shipment Day] )
                &&_count > 1
        ),
    'Table'[Index] 
    )
VAR _result =
    IF ( _index_doub <> _index, _date_1 )
RETURN
    _result

vpollymsft_0-1677490150716.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for the PBIX-File

At the beginning it seems right, but was not working in my Dataset after implementing.

I used your PBIX-File and added few new rows with new customer_No.

I attched the New-DataJPG.JPGpicture with additional Data to check why calculation is breaking after new customer entry

Anonymous
Not applicable

Hi @Power-CJ ,

I am very sorry, I have modified my program, please try again.

Column =
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[Index] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Index] < EARLIER ( 'Table'[Index] )
                && 'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
        )
    )
VAR _2count =
    CALCULATE (
        COUNT ( 'Table'[Shipment Day] ),
        FILTER (
            'Table',
            'Table'[Shipment Day] = EARLIER ( 'Table'[Shipment Day] )
                && 'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
        )
    )
VAR _shang2 =
    CALCULATE (
        MIN ( 'Table'[Index] ),
        FILTER (
            'Table',
            _2count > 1
                && 'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
                && 'Table'[Shipment Day] = EARLIER ( 'Table'[Shipment Day] )
        )
    )
VAR _nextday =
    CALCULATE (
        MAX ( 'Table'[Shipment Day] ),
        FILTER (
            'Table',
            'Table'[Sell-to-Customer] = EARLIER ( 'Table'[Sell-to-Customer] )
                && 'Table'[Index] = _1
        )
    )
RETURN
    IF (
        _2count > 1
            && 'Table'[Index] = _shang2,
        _nextday,
        IF ( _2count > 1 && 'Table'[Index] <> _shang2, BLANK (), _nextday )
    )

vpollymsft_0-1677547212420.png

 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello,

no problem - thanks a lot for the optimizing of the code.

I have problems to implement the DAX-Code in a calculated Column.

After some time PBI break up, becaus of limited capacity.

My Table in the Dataset has about 150.000 rows.

I think the DAX Code is to complex for big Tables.

 

Anonymous
Not applicable

Hi @Power-CJ ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a measure.

last shipment da1y =
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = SELECTEDVALUE ( 'Table'[Sell-to-Customer] )
                && 'Table'[Index]
                    = SELECTEDVALUE ( 'Table'[Index] ) - 1
        )
    )
VAR _2 =
    CALCULATE (
        COUNT ( 'Table'[Last Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = SELECTEDVALUE ( 'Table'[Sell-to-Customer] )
                && 'Table'[Shipment Day] = SELECTEDVALUE ( 'Table'[Shipment Day] )
        )
    )
RETURN
    IF (
        _1 = BLANK (),
        BLANK (),
        IF ( _2 = 1, _1, MINX ( ALL ( 'Table' ), [Measure] ) )
    )

Or a column.

last shipment da1y col = 
VAR _1 =
    CALCULATE (
        MAX ( 'Table'[Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = EARLIER(  'Table'[Sell-to-Customer] )
                && 'Table'[Index]
                    = EARLIER( 'Table'[Index] ) - 1
        )
    )
VAR _2 =
    CALCULATE (
        COUNT ( 'Table'[Last Shipment Day] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Sell-to-Customer] = EARLIER(  'Table'[Sell-to-Customer] )
                && 'Table'[Shipment Day] = EARLIER( 'Table'[Shipment Day] )
        )
    )
RETURN
    IF (
        _1 = BLANK (),
        BLANK (),
        IF ( _2 = 1, _1, MINX (  ( 'Table' ), [Measure] ) )
    )

 

vpollymsft_0-1677466184602.png

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Polly

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

vpollymsft_1-1677466191506.png

 

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.