Forum Discussion

Harvey85's avatar
Harvey85
Icon for Helper I rankHelper I
2 years ago
Solved

Filter List of Numeric Values from other Table

Hello,

I have the following DAX formula, where I have Table_1 and Table_2 connected by Key_Campaign.

I need to add column "save_date" from Table_2 to Table_1, filtering in Table_2 the following:

 

- Table_2'[catstock] = values starting with "SEA."

- Table_2'[labor] = value "Season Leaf"

 

End_Date = MAXX(FILTER('Table_2', 'Table_1'[Key_Campaign] = 'Table_2'[Key_Campaign] && CONTAINSSTRING('Table_2'[labor], "Season Leaf") && CONTAINSSTRING('Table_2'[catstock], "SEA.")), 'Table_2'[save_date])
 
Now I have a list of values where I need to replace the condition CONTAINSSTRING('Table_2'[labor], "Season Leaf") and filter the values by Labor_Id, those who have Valid = "Yes". In this case, I should filter values 55 and 58. I have the field Labor_Id in Table_2 (but not the column "Valid").
 
LaborLabor_IdValid
Season Leaf55Yes
Season Land58Yes
Season Stat60No
 
If I'd do that manually, how could I replace the function containsstring to filter values 55 and 58 on a easy way?
 
On the other hand, should I add this table to the model or join it to Table_2? In that case, how could I easily filter the "Yes" values?
 
Thank you!!!
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi, Harvey85 

    Based on your description, I have created the following sample data:

    Table_1:

    Table_2:

    Labor_Table:

    The relationship between the tables is as follows:

    I'm using the following DAX to filter the rows with Valid = Yes:

    End_Date =
    VAR _mediumtable =
        SUMMARIZE (
            FILTER ( 'Labor_Table', 'Labor_Table'[Valid] = "Yes" ),
            'Labor_Table'[Labor_Id],
            'Labor_Table'[Labor],
            'Labor_Table'[Valid]
        )
    RETURN
        MAXX (
            FILTER (
                'Table_2',
                'Table_1'[Key_Campaign] = 'Table_2'[Key_Campaign]
                    && CONTAINSSTRING ( 'Table_2'[catstock], "SEA." )
                    && 'Table_2'[Labor_Id] = [Labor_Id]
            ),
            'Table_2'[save_date]
        )
    

    In the variables, I use FILTER to filter out the rows with Valid=Yes. And use the summarize function to summarize, the main purpose is to get the corresponding row name so that this column can be used in MAXX.
    The DAX execution result is as follows:

    I've provided the PBIX file for this time below, and it would be great if it would help you.

     

     

     

     

    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

    Jianpeng Li

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

     

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi, Harvey85 

    Based on your description, I have created the following sample data:

    Table_1:

    Table_2:

    Labor_Table:

    The relationship between the tables is as follows:

    I'm using the following DAX to filter the rows with Valid = Yes:

    End_Date =
    VAR _mediumtable =
        SUMMARIZE (
            FILTER ( 'Labor_Table', 'Labor_Table'[Valid] = "Yes" ),
            'Labor_Table'[Labor_Id],
            'Labor_Table'[Labor],
            'Labor_Table'[Valid]
        )
    RETURN
        MAXX (
            FILTER (
                'Table_2',
                'Table_1'[Key_Campaign] = 'Table_2'[Key_Campaign]
                    && CONTAINSSTRING ( 'Table_2'[catstock], "SEA." )
                    && 'Table_2'[Labor_Id] = [Labor_Id]
            ),
            'Table_2'[save_date]
        )
    

    In the variables, I use FILTER to filter out the rows with Valid=Yes. And use the summarize function to summarize, the main purpose is to get the corresponding row name so that this column can be used in MAXX.
    The DAX execution result is as follows:

    I've provided the PBIX file for this time below, and it would be great if it would help you.

     

     

     

     

    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

    Jianpeng Li

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