Forum Discussion

KarlConstruct's avatar
KarlConstruct
Frequent Visitor
6 years ago

Need Help Writing a Dated Difference Formula

I have a txt file brought into PowerBI via a sharepoint folder, and its a list of transmitted documents and the dates in which each transmission happened.  I don't necessarily care about all of the correspondence that happened back and forth with these documents. I only care about the earliest date and the latest date, so i can come up with a dated difference. 

 

Below is an example of the type of data i'm working with. The rows colored in orange and red are seperate packages (i can tell that by the description/submittal ID & the Sequence column). There are dates inbetween the first and last date, but I am unsure how to ignore the data in the middle of the first and last dates. 

 

Any help/advice would be appreciated. Thanks! 

 

 

 

12 Replies

  • You can created calculated columns like these:

    Earliest Date =
    CALCULATE ( MIN ( Table[Sent Date] ), ALLEXCEPT ( Table, Table[Filename] ) )
    
    Latest Date =
    CALCULATE ( MAX ( Table[Sent Date] ), ALLEXCEPT ( Table, Table[Filename] ) )
    

    And then create another column to get the difference.

  • v-lid-msft's avatar
    v-lid-msft
    Community Support

    Hi KarlConstruct ,

     

    We can filter the rows of first date and the last date in power query editor if you need.

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc67DcAgDEDBXVyDZPMNZcIYiP3XSAQNymuvujHkFidBrXk1r0Gm+1EkJVImlUXPSZV0kRrIlGSkve8nRVIiZVIhVdK3ny8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Name = _t, Date = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Date", type date}}),
        Test = Table.SelectRows(
                    #"Changed Type",
                    each let d = [Date],
                             n = [Name],
                             t = Table.SelectRows(#"Changed Type", each [Name]=n),
                             isMin = List.Contains(Table.ToList(Table.TransformColumnTypes(Table.SelectColumns(Record.ToTable(Table.Min(Table.SelectColumns(t,"Date"),"Date")),"Value"),{{"Value",type text}})),Date.ToText(d)),
                             isMax = List.Contains(Table.ToList(Table.TransformColumnTypes(Table.SelectColumns(Record.ToTable(Table.Max(Table.SelectColumns(t,"Date"),"Date")),"Value"),{{"Value",type text}})),Date.ToText(d))
                          in 
                            isMin or isMax
                )
    in
        Test

     

     

    The formula may need to do some change based on the type and name of columns.


    BTW, pbix as attached.

     

    Best regards,

    Community Support Team _ Dong Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • v-lid-msft's avatar
    v-lid-msft
    Community Support

    Hi KarlConstruct ,

     

    How about the result after you follow the suggestions mentioned in my original post?Could you please provide more details about it If it doesn't meet your requirement?


    Best regards,

    • KarlConstruct's avatar
      KarlConstruct
      Frequent Visitor

      Hello, 

       

      I incorporated your formulas into my advanced editor and then i changed some fields to match my column names, but i am recieving some errors. Please see screenshots below. 

       

      Any help would be much appreciated. 

       

      Advanced editor (source removed)

       

      Submittal ID column was not found. 

      However its not being found

       

      However it is a column in the data. 

      Submittal ID is a column

       

      Overall test recieves and error as well. 

       

      Any idea what i'm doing wrong?  Please let me know if I need to provide anything else to troubleshoot this issue im having. 

       

      Thanks again. 

      • KarlConstruct's avatar
        KarlConstruct
        Frequent Visitor

        update to the advanced editor, still recieving the errors.