Forum Discussion

kbsmx's avatar
kbsmx
Frequent Visitor
5 years ago

Push Dataset Latest Date for Given Series of Rows

I have a push dataset that looks similar to this:

 

Site, Status, Latitude, Longitude, Service, Service Status, Status Date

 

Given that it is a push dataset, I have lots of rows; one for each Site/Service/Status Date combination in the history.

 

In DAX visualizations, I need to show only the lastest status rows for a given Site.  Think something like the following in SQL:

 

SELECT *

FROM Table t

INNER JOIN (

SELECT Site, MAX([Status Date]) AS Latest

FROM Table

GROUP BY Site) g

ON g.Site = t.Site

WHERE [Status Date] = Latest

 

Keep in mind with a push dataset, I cannot add new tables to the model (without manipulating tables and relationships through the REST API, which I'm trying to avoid and just use the rows endpoint witht the predefined API key).

 

I've tried using GROUPBY and storing the result in a table variable, then using a NATURALINNERJOIN, however the columns returned by GROUPBY cannot be referenced by any functions other than interators.  But if you use an interator function such as MAXX, the returned date is the same as the current row date (row context vs aggregate):

 

GroupByTest =
VAR LatestSiteStatusDates = GROUPBY(RealTimeData, RealTimeData[Site], "Most Recent Status", MAXX(CURRENTGROUP(), RealTimeData[Status Date]))
VAR LatestSiteStatusJoin = NATURALINNERJOIN(LatestSiteStatusDates, RealTimeData)
RETURN CALCULATE(MAXX(LatestSiteStatusJoin, [Most Recent Status]))

 

I've also tried LOOKUPVALUE, but as previously mentioned about any function that isn't an interator, the columns in the table variable are inaccessible to it.

 

Any ideas?


Thanks!

 

Kevan

2 Replies

  • kbsmx add this measure and use it as a visual level filter where value = 1 and I think it will do it

     

    Filter Latest Row = 
    VAR __table = ALLEXCEPT ( YourTable, YourTable[Site] )
    VAR __latestDate = CALCULATE ( LASTDATE ( YourTable[Date] ), __table )
    RETURN
    ( MAX ( YourTable[Date] ) == __latestDate ) + 0

     

    Check my latest blog post Compare Budgeted Scenarios vs. Actuals I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    ⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡

     

    • kbsmx's avatar
      kbsmx
      Frequent Visitor

      parry2k - Thank you for your response and suggestion.  However, LASTDATE will not work in this scenario as the [Status Date] column contains the same date/time for each Site/Service/Status combination.  The rows for a given Site and its services are all posted at the same time using the same date/time value.  So LASTDATE will throw an exception if used in this context.