Forum Discussion

CHaines's avatar
CHaines
Advocate I
3 years ago
Solved

Dynamic sized table showing current /previous items

Help please. I want to show a list of the passengers for the selected taxi route/date, and a list of passengers for the same route the previous day. This list is not always the same length. I also wa...
  • WinterMist's avatar
    WinterMist
    3 years ago

    CHaines 

     

    So here is the solution on how to make it so that nothing appears in

    your output when both the Date & RouteID are not selected.

     

    Step 1 - Create a measure to check if BOTH the Date AND RouteID are being filtered.

     

     

    Step 2 - Select the "OUTPUT" table visual, and add the measure as a Filter on the visual.

     

     

    When the Date & RouteID are not selected, or only 1 of them is selected, no results are shown in the OUTPUT.

     

     

    However, when both Date AND RouteID are selected, then the OUTPUT shows results:

     

     

     

    NOTES:

    - In this case, I am able to select the Journey (without using the slicers) and it still works, but that is because I'm only using a single table in the model for all the data.  Depending on your model, you might not be able to do this, and be forced to use slicers.

     

    - You will also notice that the output is sorted in alphabetical order.  That's because per the data provided, there is nothing else to sort the name by.  So it will not appear in the same order as it did in the full table.

     

    Full Table Order: Ewan, Niamh, Cillian

    OUTPUT Order: Cillian, Ewan, Niamh

     

    I'll get back to you on the Previous Journey, but this should get you started.

     

    Regards,

    Nathan

  • tamerj1's avatar
    3 years ago

    Hi CHaines 
    Please refer to attached sample file with the proposed solution. Hope this is what you're looking for

    Most Recent Journey = 
    VAR CurrentIndex = SELECTEDVALUE ( 'Index'[Value] )
    VAR T1 = VALUES ( individual_details[PersonID] )
    VAR T2 = 
        ADDCOLUMNS ( 
            T1, 
            "@Index", RANKX ( T1, [PersonID],, ASC, Dense )
        )
    VAR T3 = FILTER ( T2, [@Index] = CurrentIndex )
    RETURN
        IF (
            HASONEVALUE ( journey_detail[Date] ) && HASONEVALUE ( journey_detail[RouteID] ),
            MAXX ( T3, [PersonID] )
        )
    Previous Journey = 
    VAR CurrentIndex = SELECTEDVALUE ( 'Index'[Value] )
    VAR CurrentDate = SELECTEDVALUE ( journey_detail[Date] )
    VAR T1 = 
        CALCULATETABLE ( 
            VALUES ( individual_details[PersonID] ), 
            REMOVEFILTERS ( ),
            VALUES ( individual_details[RouteID] ),
            individual_details[Date] = CurrentDate - 1 
        )
    VAR T2 = 
        ADDCOLUMNS ( 
            T1, 
            "@Index", RANKX ( T1, [PersonID],, ASC, Dense )
        )
    VAR T3 = FILTER ( T2, [@Index] = CurrentIndex )
    RETURN 
        MAXX ( T3, [PersonID] )