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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Hichamas4
Frequent Visitor

Measure/Model calculation support needed

Dear all,

I have a question and I request some support. (I am trying to solve this in Power BI but maybe its a real back-end issue)

 

In Power BI we consume a starschema where different products (Dim_Product) had different purchases in Fact_ProductTransactions.

The issue I have, some products belong to different categories and I have to calculate the leadtime of a product in each category.

 

OrderIDNameGroup-BikeGroup-CarGroup-TruckStartDateEndDate
1A1Product A1Bike Truck01/01/202101/04/2026
2A2Product A2Bike Truck01/01/202101/04/2026
3A2.5Product A3Bike Truck01/01/202101/04/2026
4A3Product A4Bike Truck03/01/202101/04/2026
5A4Product A5Bike  03/01/202101/04/2026
6A5Product A6Bike Truck01/01/202101/04/2026
7A6Product A7Bike Truck01/01/202101/04/2026
9A7Product A8Bike Truck01/01/202101/04/2026
10A8Product A9Bike  01/01/202102/04/2026
11A9Product A10Bike Truck02/01/202101/04/2026
13A58Product A11Bike Truck04/11/202401/04/2026
14A59Product A12Bike Truck04/11/202427/03/2026
15A60Product A13Bike Truck14/11/202431/03/2026
16A61Product A14Bike Truck14/11/202401/04/2026
17A62Product A15Bike Truck12/12/202401/04/2026
18A11Product A16BikeCar 04/01/202131/03/2026
19A12Product A17BikeCar 04/01/202131/03/2026
20A13Product A18BikeCar 04/01/202131/03/2026
21A53Product A19Bike Truck12/01/202131/03/2026
22A52Product A20Bike Truck04/01/202131/03/2026
23A55Product A21  Truck31/03/202231/03/2026
24A56Product A22BikeCar 30/06/202227/03/2026
25A14Product A23BikeCar 03/01/202131/03/2026
30A19Product A24BikeCar 04/01/202131/03/2026
31A20Product A25Bike Truck04/01/202101/04/2026
32A21Product A26Bike Truck04/01/202101/04/2026
33A31Product A27Bike Truck04/01/202102/04/2026
34A22Product A28BikeCar 03/01/202131/03/2026
35A23Product A29  Truck04/01/202101/04/2026
37A25Product A30 Car 04/01/202131/03/2026
38A26Product A31  Truck03/01/202101/04/2026
39A27Product A32 Car 04/01/202131/03/2026
41A49Product A33  Truck22/04/202131/03/2026
42A29Product A34  Truck04/01/202131/03/2026
43A30Product A35 Car 04/01/202131/03/2026
44A32Product A36  Truck04/01/202101/04/2026

 

You can see that sometimes a category (Bike-Car-Truck) is blank if we would like to:

1. Use all three columns as slicer (This I can solve using Field Parameter option)

2. Calculate leadtime (DateDiff between start and end date in days) based on the following conditions:

a. Blank should be ignored

b. Overalpping start and end date need to be ignored (We dont want double leadtime, if they run at the same time then only take 1 or deduct the overlapping leadtime)

c. Gaps between products (If a product starts in a year after the previous product ends) need to be ignored or deducted from total leadtime

 

So far what I though about. Maybe some more scenario's will promt up in the next days as I am analyzing the data and all modelling options.

3 REPLIES 3
v-hashadapu
Community Support
Community Support

Hi @Hichamas4 , Thank you for reaching out to the Microsoft Community Forum.

 

We find the answer shared by @Zanqueta  is appropriate. Can you please confirm if the solution worked for you. It will help others with similar issues find the answer easily.
Thank you @Zanqueta  for your valuable response.

danextian
Super User
Super User

Hi @Hichamas4 

Using the same sample data provided, please show your expected result and the explanation behind.

Note: I had to emphasize using the same sample data provided as there were users who provided the expected result but used a different data.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Zanqueta
Super User
Super User

Hi @Hichamas4

 

You are facing a scenario where products may belong to multiple categories (Bike, Car, Truck), and where each product-category combination has associated date intervals. Your objective is to calculate lead time in days per category while applying three conditions:

Categories left blank must be ignored.

Overlapping date intervals must not be counted twice.

Gaps (periods where no interval exists) must not contribute to the total lead time.

This is fundamentally an “interval-union” problem, where multiple date ranges per product and category need to be treated as a single continuous timeline.

1. Recommended Data Modelling Approach

Using separate columns for categories (Group-Bike, Group-Car, Group-Truck) complicates the calculations.
A more suitable modelling approach is to normalise the categories by creating a bridge table.

Proposed structure

  • Dim_Product
    ProductID, ProductName
  • Bridge_ProductCategory
    ProductID, Category
    (One row per category, for example Bike, Car or Truck)
Fact_ProductTransactions
ProductID, StartDate, EndDate
This structure allows analytical filtering by category without dealing with blank columns, and avoids complex conditional logic.

Power Query transformation (conceptual steps)

Duplicate the raw product table.

Unpivot the three category columns.

Remove rows where the category value is blank.

Produce a table containing only ProductID and Category.

This becomes your bridge table linking products to categories.

2. Lead Time Calculation Strategy

The most robust method for handling overlapping intervals and gaps is to use a Date dimension and count the number of distinct days for which at least one interval is active.
Because a day is counted only once, overlapping intervals do not accumulate duplicate lead-time.
Days without an interval automatically represent gaps and are excluded.

Required tables

Dim_Date

Fact_ProductTransactions

Dim_Product

Bridge_ProductCategory

Dim_Category

Lead Time Measure (DAX):

Leadtime Days :=
VAR ActiveDates =
    FILTER(
        ALL('Dim_Date'[Date]),
        CALCULATE(
            COUNTROWS('Fact_ProductTransactions'),
            'Dim_Date'[Date] >= 'Fact_ProductTransactions'[StartDate]
                && 'Dim_Date'[Date] <= 'Fact_ProductTransactions'[EndDate]
        ) > 0
    )
RETURN
    COUNTROWS(ActiveDates)

 

This measure returns the number of days in which at least one interval is active in the current filter context (Product, Category, etc.). Overlaps and gaps are handled implicitly.

3. When to Move Logic to the Back‑End

If the volume of data is high, or if the Date dimension spans many years, the DAX approach may become slow.
In that case, it is advisable to consolidate intervals in Power Query or in a SQL back‑end by merging overlapping periods per Product and Category before loading them into the model.
Lead time can then be calculated with a simple DAX expression using SUMX over consolidated intervals.

4. Summary of Both Approaches

Option A – DAX solution (suitable for moderate volumes)
  • Normalise category columns into a bridge table.
  • Use a Date table.

Calculate lead time by counting distinct active days.

Option B – Back‑end consolidation (suitable for large volumes)
  • Merge overlapping date intervals per Product and Category before loading to Power BI.

Use simple DAX to sum the lengths of consolidated intervals.

 

DISCLAIMER: While I wrote a draft of this answer, I used Copilot to create a longer, more detailed step-by-step description to make it easier to apply.
 

If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster.
Connect with me on LinkedIn

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.