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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors