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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
tykio
New Member

How to get the penultimate order date per customer from order data

Hi Guys,
I want to ask how to take out the penultimate order date of each customer,I have tried using the following formula,but doesn't work 
螢幕擷取畫面 2022-08-07 134616.jpg

penultimate order date=
CALCULATE(
    MIN('order'[Order Date],
    TOPN(
        2,
        'order',
        'order'[Order Date]
    )
))



thanks for all the tips and help @!

1 ACCEPTED SOLUTION

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Picture2.png

 

New Table =
VAR _lastorderdate =
    ADDCOLUMNS (
        VALUES ( Customer[Customer ID] ),
        "@LastOrderDate",
            MAXX (
                FILTER ( 'Order', 'Order'[Customer ID] = EARLIER ( Customer[Customer ID] ) ),
                'Order'[Order Date]
            )
    )
VAR _penultimatedate =
    ADDCOLUMNS (
        _lastorderdate,
        "PenultimateOrderDate",
            MAXX (
                FILTER (
                    'Order',
                    'Order'[Customer ID] = EARLIER ( Customer[Customer ID] )
                        && 'Order'[Order Date] < [@LastOrderDate]
                ),
                'Order'[Order Date]
            )
    )
RETURN
    _penultimatedate

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

7 REPLIES 7
tykio
New Member

@Jihwan_Kim  thanks for reply ,please check the URL 
https://drive.google.com/file/d/1sgll6K_YHXMRdU4VEPk3QQ8XckJCvu-l/view?usp=sharing
I want to add the last consumption date and the penultimate consumption date to the output data, and then calculate the member's consumption cycle.
Thanks for your kindly help 

Hi,

Sorry but your pbix file looks like below and I cannot proceed.

Did you mean that you want to create a calcluated table instead of the visualization?

 

 

Picture1.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

@Jihwan_Kim thanks for reply

Yes,i want to create a calcluated table 🙂 thanks for your help

Hi,

Please check the below picture and the attached pbix file.

It is for creating a new table.

 

Picture2.png

 

New Table =
VAR _lastorderdate =
    ADDCOLUMNS (
        VALUES ( Customer[Customer ID] ),
        "@LastOrderDate",
            MAXX (
                FILTER ( 'Order', 'Order'[Customer ID] = EARLIER ( Customer[Customer ID] ) ),
                'Order'[Order Date]
            )
    )
VAR _penultimatedate =
    ADDCOLUMNS (
        _lastorderdate,
        "PenultimateOrderDate",
            MAXX (
                FILTER (
                    'Order',
                    'Order'[Customer ID] = EARLIER ( Customer[Customer ID] )
                        && 'Order'[Order Date] < [@LastOrderDate]
                ),
                'Order'[Order Date]
            )
    )
RETURN
    _penultimatedate

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

I think there are many ways to solve the problem, but I tried to use TOPN function like what it is in your measure.

Please check if it suits your requirement.

 

Untitled.png

 

penultimate order date = 
IF (
    COUNTROWS ( 'Order' ) >= 2
        && HASONEVALUE ( Customer[Customer ID] ),
    CALCULATE (
        MIN ( 'Order'[Order Date] ),
        KEEPFILTERS (
            TOPN (
                2,
                ALL ( 'Order'[Order Date] ),
                CALCULATE ( MAX ( 'Order'[Order Date] ) ), DESC
            )
        )
    )
)

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Hi @Jihwan_Kim 
Thanks for your reply 🙂 very useful

 

there is another question,

Is there an easier way if I want to output the results as a data rather than a report?

 

so many thanks!

Hi,

Thank you for your message.

Sorry that it is difficult to understand your last question.

Could you please share your sample pbix file's link with how the expected result looks like?


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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