How do I calculate the average time between two events for each customer

0 votes
How do I calculate the average time between two events for each customer?

i  need a Power BI measure that calculates the average time between two specific events for each customer, such as the time between when an order is placed and when it is delivered. The calculation should be dynamic, adjusting based on filters like time periods or customer groups. How can I use DAX functions like DATEDIFF or AVERAGEX to compute the average time and ensure it adjusts with user filters?
Apr 1, 2025 in Power BI by Evanjalin
• 36,180 points
589 views

1 answer to this question.

0 votes

To calculate the average time between two specific events for each customer in Power BI, you can use DAX functions like DATEDIFF, AVERAGEX, and CALCULATE to compute the time difference dynamically. Below is the approach to achieve this:

Step-by-step process:

  1. Define the Two Events: You'll need to have columns that represent the timestamps for the two events (e.g., "Order Date" and "Delivery Date") in your dataset.

  2. Use DAX Functions:

    • DATEDIFF: Calculates the difference between two dates in a specified time unit (e.g., days, hours).

    • AVERAGEX: Calculates the average of an expression evaluated over a table, which allows you to iterate over each customer.

Example DAX Measure:

​Average Time Between Events = 
AVERAGEX(
    VALUES(Orders[CustomerID]), 
    DATEDIFF(
        FIRSTNONBLANK(Orders[OrderDate], Orders[OrderDate]), 
        FIRSTNONBLANK(Orders[DeliveryDate], Orders[DeliveryDate]), 
        DAY
    )
)

Explanation:

  • VALUES(Orders[CustomerID]): This returns a unique list of customer IDs, so the AVERAGEX function calculates the measure for each customer.

  • FIRSTNONBLANK(Orders[OrderDate], Orders[OrderDate]): This retrieves the first non-blank order date for each customer.

  • FIRSTNONBLANK(Orders[DeliveryDate], Orders[DeliveryDate]): This retrieves the first non-blank delivery date for each customer.

  • DATEDIFF: This calculates the difference between the order date and the delivery date in days (you can change DAY to HOUR, MINUTE, etc., depending on the time unit you want).

  • AVERAGEX: This calculates the average time across all customers in the filtered context, which adjusts dynamically based on applied filters like customer groups or time periods.

Result:

  • This measure will return the average time between the two events (order and delivery) for each customer, adjusting based on any filters applied (e.g., by customer, date range, etc.).

  • The result will be dynamic and update according to the filters or slicers selected by the user.

answered Apr 1, 2025 by anonymous
• 36,180 points

Related Questions In Power BI

0 votes
1 answer

How do I calculate the percentage contribution of each category while considering multiple slicers?

You can calculate the percentage contribution dynamically ...READ MORE

answered Mar 25, 2025 in Power BI by anonymous
• 36,180 points
874 views
0 votes
1 answer

How can I use DAX to calculate the difference between two non-contiguous periods?

In Power BI, DAX provides the solution ...READ MORE

answered Apr 1, 2025 in Power BI by anonymous
• 36,180 points
470 views
0 votes
1 answer

How do I ensure the deployment pipeline in Power BI maintains versioning for each report?

1. Make use of OneLake/Workspace History (Limited) You ...READ MORE

answered Jun 3, 2025 in Power BI by anonymous
• 36,180 points
356 views
0 votes
1 answer

How do I calculate difference between consecutive rows and columns?

There are two ways through which you ...READ MORE

answered May 21, 2019 in Power BI by Avantika
• 1,520 points
12,700 views
0 votes
1 answer

Displaying Table Schema using Power BI with Azure IoT Hub

Answering your first question, Event Hubs are ...READ MORE

answered Aug 1, 2018 in IoT (Internet of Things) by nirvana
• 3,090 points
2,492 views
+1 vote
1 answer

Unable to install connector for Power Bi and PostgreSQL

I think the problem is not at ...READ MORE

answered Aug 22, 2018 in Power BI by nirvana
• 3,090 points
3,833 views
+2 votes
2 answers

Migrate power bi collection to power bi embedded

I agree with Kalgi, this method is ...READ MORE

answered Oct 11, 2018 in Power BI by Hannah
• 18,520 points
2,653 views
+1 vote
1 answer

Connect power bi desktop to dataset and create custom reports

Open power bi report nd sign in ...READ MORE

answered Oct 10, 2023 in Power BI by Monika kale

edited Mar 5, 2025 2,717 views
0 votes
1 answer

How do I dynamically calculate the first and last transaction date for each customer?

Calculation of the first transaction date and ...READ MORE

answered Apr 1, 2025 in Power BI by anonymous
• 36,180 points
747 views
0 votes
1 answer

I want to calculate the distinct count of active customers but only for the last three completed months—how can I do this in DAX?

To calculate the distinct count of active ...READ MORE

answered Mar 10, 2025 in Power BI by anonymous
• 36,180 points
755 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP