Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
Dear all
I have the following data
| Date | Product | Line # |
| 1-Jan-21 | Product A | Line 1 |
| 2-Jan-21 | Product A | Line 1 |
| 3-Jan-21 | Product A | Line 1 |
| 4-Jan-21 | Product A | Line 1 |
| 5-Jan-21 | Product A | Line 3 |
| 6-Jan-21 | Product A | Line 3 |
| 7-Jan-21 | Product A | Line 3 |
| 8-Jan-21 | Product C | Line 1 |
| 9-Jan-21 | Product C | Line 1 |
| 10-Jan-21 | Product C | Line 1 |
How can I calculate the duration with dax like that:
| Product | Duration | From | To | Line # |
| Product A | 4 | 1-Jan-21 | 4-Jan-21 | Line 1 |
| Product A | 3 | 5-Jan-21 | 7-Jan-21 | Line 3 |
| Product C | 3 | 8-Jan-21 | 10-Jan-21 | Line 1 |
@amrabousamra
You can easily do it in Power Query as well.
Select Product and Line then Group as follows:
Create a blank Query, go to the Advanced Editor, clear the existing code, and paste the codes give below and follow the steps.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtT1SszTNTJU0lEKKMpPKU0uUXAEsn0y81IVDJVidaKVjAiqMCaowoSgClM8KozBKswIqjAnqMICU4UzqjssCaowNMCvJBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Product = _t, #"Line #" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Product", "Line #"}, {{"Start Date", each List.Min([Date]), type nullable date}, {"End Date", each List.Max([Date]), type nullable date}, {"Days", each Table.RowCount(_), Int64.Type}})
in
#"Grouped Rows"
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 7 | |
| 5 | |
| 4 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 19 | |
| 10 | |
| 6 | |
| 6 | |
| 5 |