Forum Discussion

nicholas058's avatar
nicholas058
Frequent Visitor
2 years ago

Creating a Measure/Column Which Shows the Most Recent Value and one which shows the Oldest

Good Morning, 

 

My first post on this forum, so I apologize if I'm not wording the question appropriately. However, I'm struggling to figure this out based on the existing articles I've looked at, so I'm hoping a specific question will provide the answers I need. 

 

My sales organization wants to see a table of original values, and then the most recent values. I have this data located within a history table, however, I'm not sure how to present it in a table. 

 

I need to be able to pull the latest "NewValue" by whatever the most recent date of "CreatedDate". Likewise, I'm needing a way to show the the oldest "OldValue" by the earliest date of "CreatedDate" 

 

The dataset looks like this...

 

 

Operations would like to see something like this (just throwing some random numbers in the graph below to clarify)

 

parentidOriginal Max WeightNegotiated Max Weight
126
247
357
445.5
....

 

7 Replies

  • Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
    If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
    Please show the expected outcome based on the sample data you provided.

    If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi nicholas058 ,

    I have created a simple sample, please refer to my pbix file to see if it helps you.

    Create measures.

    Old = var _1=minx(FILTER(ALL('Table'),'Table'[ID]=SELECTEDVALUE('Table'[ID])),'Table'[DATE])
    return
    IF(MAX('Table'[DATE])=_1,MAX('Table'[VALUE]),BLANK())
    old_re = MAXX(FILTER(ALL('Table'),'Table'[ID]=SELECTEDVALUE('Table'[ID])),[Old])

    And so on.

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

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

     

     

     

     

  • nicholas058's avatar
    nicholas058
    Frequent Visitor

    Hi Anonymous 

     

    This is close, but not exactly what I'm trying to accomplish. 

     

    I would like to create a measure that shows the most recent value, and another that shows the oldest value, which will allow me to have only one instance of the quote in the row. 

     

    Here is a pictured version. I've also attached this much abbreviated datasheet, as well as a dummy project file to play with. 

     

    Abbreviated Data Excel 

    Sample PBI 

      • nicholas058's avatar
        nicholas058
        Frequent Visitor

        Hey there, this was super helpful, however I'm running into another issue! It refuses to aggregate these totals. As you see in the example above, the totals are just the last line. I need to know the total sum of these changes. 

         

        In my report....

         

        For sample data, you can still use the PBIX you provided above

         

         



    • lbendlin's avatar
      lbendlin
      Super User
      let
          Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jc9LDoMwDEXRraCMqYh/L+A1tFI7Rux/Gy2kQkmJClPr6Nqe5/C636IABA19oMEGls6ctHs+PgOEpW8bceZsrDQw2QxWA1dpdCpjrjGb8Y+R6dhJFIt74EznhiybVBqztBniFbFr47EDoi/SCgF1CReQjK11v8j20vIG", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Line Name" = _t, CreatedDate = _t, NewValue = _t]),
          #"Changed Type" = Table.TransformColumnTypes(Source,{{"Line Name", type text}, {"CreatedDate", type datetime}, {"NewValue", Int64.Type}}),
          #"Grouped Rows" = Table.Group(#"Changed Type", {"Line Name"}, {{"Min Date", each List.Min([CreatedDate]), type nullable datetime}, {"Max Date", each List.Max([CreatedDate]), type nullable datetime}, {"Rows", each _, type table [Line Name=nullable text, CreatedDate=nullable datetime, NewValue=nullable number]}}),
          #"Added Custom" = Table.AddColumn(#"Grouped Rows", "NewValue at Min Date", each Table.SelectRows([Rows],(k)=> k[CreatedDate]=[Min Date])[NewValue]{0},Int64.Type),
          #"Added Custom1" = Table.AddColumn(#"Added Custom", "NewValue at Max Date", each Table.SelectRows([Rows],(k)=> k[CreatedDate]=[Max Date])[NewValue]{0},Int64.Type),
          #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Line Name", "Min Date", "Max Date", "NewValue at Min Date", "NewValue at Max Date"})
      in
          #"Removed Other Columns"

      How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".