Forum Discussion

olepropell's avatar
olepropell
New Member
5 years ago
Solved

Filter visuals with position data to show only current position per tracking unit

Hi. I use Direct Query and receive a dataset with positions from tracking units. Each tracking has a timestamp.

 

I have two visuals, a table and and a map.

 

What I want to achieve is a button for showing only the latest position per unit. 

 

Example: I want to move from this view:

 

To this view:

Any assistance will be highly appreciated 🙂

 

  • Hi olepropell ,

     

    I created a slicer button and a measure to do this.

     

    Create a table for the slicer mine has the following values:

     

    Values

    All Values
    Latest Values

     

    Now create the following measure:

    Latest_Values =
    VAR temp_table =
        SUMMARIZE (
            ALL ( 'Table'[TrackerID], 'Table'[Date], 'Table'[Lat], 'Table'[Long] ),
            'Table'[TrackerID],
            "DATE", MAX ( 'Table'[Date] )
        )
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Period Selection'[Values] ),
            "All Values", 1,
            IF (
                SELECTEDVALUE ( 'Table'[Date] )
                    = MAXX (
                        FILTER ( temp_table, 'Table'[TrackerID] = MAX ( 'Table'[TrackerID] ) ),
                        [DATE]
                    ),
                1
            )
        )

    Now add this has filter on your visualizations and select all non blank vlaues

     

    Result below and in attach PBIX file.

     
     

     

     

     

6 Replies

  • Hi olepropell ,

     

    I created a slicer button and a measure to do this.

     

    Create a table for the slicer mine has the following values:

     

    Values

    All Values
    Latest Values

     

    Now create the following measure:

    Latest_Values =
    VAR temp_table =
        SUMMARIZE (
            ALL ( 'Table'[TrackerID], 'Table'[Date], 'Table'[Lat], 'Table'[Long] ),
            'Table'[TrackerID],
            "DATE", MAX ( 'Table'[Date] )
        )
    RETURN
        SWITCH (
            SELECTEDVALUE ( 'Period Selection'[Values] ),
            "All Values", 1,
            IF (
                SELECTEDVALUE ( 'Table'[Date] )
                    = MAXX (
                        FILTER ( temp_table, 'Table'[TrackerID] = MAX ( 'Table'[TrackerID] ) ),
                        [DATE]
                    ),
                1
            )
        )

    Now add this has filter on your visualizations and select all non blank vlaues

     

    Result below and in attach PBIX file.

     
     

     

     

     

    • olepropell's avatar
      olepropell
      New Member

      Hi MFelix.

       

      This really helped and I am trying to implement this into my model now. Just to check: The temp table in the measure must be built with all columns I want to use in my visuals, correct?

       

      In my example each tracking also have data for Knots, Course, Battery, Transport and Trigger.

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        Hi olepropell ,

         

        Not necessarily, you must use the ones that give you most information you need in this case the date, lat, long and ID, should be enough, if you see this does not return expected result then add the rest of the columns.

  • I am having trouble getting all the data into the temp-table. Transport and Trigger is collected from two help-tables, Knot is a measure in the main table (TrackingsDQ) while Course and Battery are regular data fields in the main table.

     

    If I for example try to collect Transport from the help table dTransport this is what happens:

     

    Are there other and more straight-forward strategies for singeling out the latest rows? A more sophisticated time slicer or other things?

     

     

    • v-robertq-msft's avatar
      v-robertq-msft
      Icon for Community Support rankCommunity Support

      Hi, olepropell 

      According to your DAX formula, I think the problem exists in the SUMMARIZE() function you used, you can’t use a column from another table here:

       

      You can try to nest a RELATED() function in the outer layer of this column, but you should make sure the two tables must have a relationship first.

      RELATED(dTransport[Transport])

      What’s more, to get more detailed help from other experts, I suggest you to open a new case in the community. Because most communitors can’t see your question because it’s under another topic.

      Thank you very much!

      How to Get Your Question Answered Quickly 

       

      Best Regards,

      Community Support Team _Robert Qin

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

  • v-robertq-msft's avatar
    v-robertq-msft
    Icon for Community Support rankCommunity Support

    Hi, olepropell 

    Have  MFelix’s reply helped you to solve this problem?

    If so, would you like to mark his reply as a solution so that others can learn from it too?

    If not, I suggest you to post some sample data or your test pbix file (without sensitive data) and we can help you in advance.

    Thanks in advance!

    How to Get Your Question Answered Quickly 

     

    Best Regards,

    Community Support Team _Robert Qin

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