Forum Discussion

BaileyL's avatar
BaileyL
Frequent Visitor
2 years ago
Solved

Creating an Index for filtered data

Hello   Beginner question, This the the filtered table that I currently use on a graph (X-ID, Y-M_DAYS_TO_COMPLETE). I am filtering by type, this table returns a specific one, which starts at 5249...
  • OwenAuger's avatar
    2 years ago

    Hi BaileyL 

    Here's an example of one approach (PBIX attached)

     

    1. I loaded your sample data into a table called 'Data'.

    2. Created an Index table with single column Index[Index].

    The Index column contains integers from 1 to the distinct number of values of Data[ID] across the entire dataset (16 in this example but would actually be larger):

    3. Created these measures:

     

    M Days to Complete Sum = 
    SUM ( Data[M_DAYS_TO_COMPLETE] )
    M Days to Complete Sum by Index = 
    VAR IDValuesAllselected =
        CALCULATETABLE (
            SUMMARIZE ( Data, Data[ID] ),
            ALLSELECTED ( )
        )
    VAR IndexValues =
        VALUES ( 'Index'[Index] )
    VAR Index_ID =
        GENERATE (
            IndexValues,
            INDEX ( 'Index'[Index], IDValuesAllselected )
        )
    RETURN
        CALCULATE (
            [M Days to Complete Sum],
            Index_ID
        )

     

    The 2nd measure determines the ID corresponding to the currently filtered Index using the INDEX function.

    It then applies this as a filter to calculate the underlying measure.

    This could also have been written another way by determining the indexes of all ID values, then selecting the ID(s) corresponding to the currently filtered Index(es)

     

    4. Create visuals displaying the 1st measure by ID and the 2nd measure by Index:

    Hopefully I've understood your requirements correctly. Please post back if needed! 🙂

     

    Regards