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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
amrabousamra
Regular Visitor

Calculate how many days product run in each production line

Dear all

I have the following data

DateProductLine #
1-Jan-21Product ALine 1
2-Jan-21Product ALine 1
3-Jan-21Product ALine 1
4-Jan-21Product ALine 1
5-Jan-21Product ALine 3
6-Jan-21Product ALine 3
7-Jan-21Product ALine 3
8-Jan-21Product CLine 1
9-Jan-21Product CLine 1
10-Jan-21Product CLine 1

 

 

How can I calculate the duration with dax like that:

ProductDurationFromToLine #
Product A41-Jan-214-Jan-21Line 1
Product A35-Jan-217-Jan-21Line 3
Product C38-Jan-2110-Jan-21Line 1
1 REPLY 1
Fowmy
Super User
Super User

@amrabousamra 

You can easily do it in Power Query as well.

Select Product and Line then Group as follows:

 

Fowmy_0-1610799332119.png

Screenshot 2021-01-16 151707.jpg


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"



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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