Forum Discussion

prakash11440278's avatar
prakash11440278
Post Prodigy
7 years ago
Solved

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:0...
  • dax's avatar
    dax
    6 years ago

    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.