cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

Dax formula help

Hi All,

Can you please provide the dax formula for the below.
Input data:
Vehicle Date&Time Production
Bike 6/1/18 12:00 AM 100
Bike 6/1/18 1:00 AM 200
Bike 6/1/18 2:00 AM 221
Bike 6/1/18 3:00 AM 321
Bike 6/1/18 4:00 AM 432
Bike 6/1/18 5:00 AM 470
Bike 6/1/18 6:00 AM 500
Bike 6/1/18 7:00 AM 520
Bike 6/1/18 8:00 AM 530
Car 6/1/18 12:00 AM 120
Car 6/1/18 1:00 AM 220
Car 6/1/18 2:00 AM 250
Car 6/1/18 3:00 AM 270
Car 6/1/18 4:00 AM 300

Expected Result:
Vehicle Segment Production
Bike 12-1 AM 100
Bike 1-2 AM 21
Bike 2-3 AM 100
Bike 3-4 AM 111
Bike 4-5 AM 38
Bike 5-6 AM 30
Bike 6-7 AM 20
Bike 7-8 AM 10
Car 12-1 AM 100
Car 1-2 AM 30
Car 2-3 AM 20
Car 3-4 AM 30

Thanks in advance
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Dax formula help

Hi prakash11440278 , 

You could try to create a index column by M code like below 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdA9CoAwDAXgq5TMgk1if3BTZ08gDg4O4ub9BxWhKfjWfAlJ3rLQeJw7NRRbbjk7lt57N8xPhb2ntfk1FBfoNi/CwLW4Qu+KdyrAg3lC+2PxAO9L5oI8m+vn03bhfAR59T7gKp0A2MKRBNiy0fe39QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Vehicle = _t, #"Date&Time" = _t, Production = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Vehicle", type text}, {"Date&Time", type datetime}, {"Production", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Vehicle"}, {{"a", each _, type table [Vehicle=text, #"Date&Time"=datetime, Production=number, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "index", each Table.AddIndexColumn([a], "in",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"a"}),
    #"Expanded index" = Table.ExpandTableColumn(#"Removed Columns", "index", {"Date&Time", "Production", "in"}, {"Date&Time", "Production", "in"})
in
    #"Expanded index"

 Then use below measure, you could refer to my sample

Measure = 

  SUM(T3[Production])
        - CALCULATE (SUM(T3[Production])
            ,
            FILTER ( ALLEXCEPT( T3,T3[Vehicle]), T3[in]=MIN(T3[in])-1 )
        )

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Super User
Super User

Re: Dax formula help

Hey,

 

you can solve your requirement using  the static segmentation that is described in this article: https://www.daxpatterns.com/static-segmentation/

Create a calculated column in your table that "segments" the hours, and then use the new column.

 

Hopefully this is what you are looking for.

 

Regards,

Tom

Hamburg - Germany
If I answer your question, please mark my post as solution, this will also help others.
I accept Kudos :-), If you find my post helpful.

Proud to be a Datanaut!

Re: Dax formula help

Hi Tom,

Looks like the numbers are cumulative sum. How can we calculate difference between current hour and previous hour for each vehicle type.

Thanks
Super User
Super User

Re: Dax formula help

Hey,

 

please provide a pbix/xlsx file that contains sample data, but still reflects your data model, meaning create sample data for all the tables necessary to re-create your "issue", upload the file(s) to onedrive or dropbox and share the link.

 

Regards,

Tom

Hamburg - Germany
If I answer your question, please mark my post as solution, this will also help others.
I accept Kudos :-), If you find my post helpful.

Proud to be a Datanaut!

Re: Dax formula help

Community Support Team
Community Support Team

Re: Dax formula help

Hi prakash11440278 , 

You could try to create a index column by M code like below 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdA9CoAwDAXgq5TMgk1if3BTZ08gDg4O4ub9BxWhKfjWfAlJ3rLQeJw7NRRbbjk7lt57N8xPhb2ntfk1FBfoNi/CwLW4Qu+KdyrAg3lC+2PxAO9L5oI8m+vn03bhfAR59T7gKp0A2MKRBNiy0fe39QY=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Vehicle = _t, #"Date&Time" = _t, Production = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Vehicle", type text}, {"Date&Time", type datetime}, {"Production", Int64.Type}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1),
    #"Grouped Rows" = Table.Group(#"Added Index", {"Vehicle"}, {{"a", each _, type table [Vehicle=text, #"Date&Time"=datetime, Production=number, Index=number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "index", each Table.AddIndexColumn([a], "in",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"a"}),
    #"Expanded index" = Table.ExpandTableColumn(#"Removed Columns", "index", {"Date&Time", "Production", "in"}, {"Date&Time", "Production", "in"})
in
    #"Expanded index"

 Then use below measure, you could refer to my sample

Measure = 

  SUM(T3[Production])
        - CALCULATE (SUM(T3[Production])
            ,
            FILTER ( ALLEXCEPT( T3,T3[Vehicle]), T3[in]=MIN(T3[in])-1 )
        )

Best Regards,
Zoe Zhi

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
New Topics Started Badges Coming

New Topics Started Badges Coming

We're releasing new versions of the badge that everyone's talking about. ;) Check your inbox for notifications.

MBAS 2020

Save the new date (and location)!

Our business applications community is growing—so we needed a different venue, resulting in a new date and location. See you there!

Difinity Conference

Difinity Conference

The largest Power BI, Power Platform, and Data conference in New Zealand

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

Top Solution Authors
Top Kudoed Authors (Last 30 Days)