Forum Discussion

NilR's avatar
NilR
Post Patron
2 years ago
Solved

Date Filter Help

I would like to write Dax to select all 3 highlighted rows. I wrote this and it does not grab all 3 row values.

LOGIC: Date >= _ENR_DATE &&  Date <= _Max_date, but I encountered dates that are greater than VAR _Max_Date

 

 

 

var _Max_Date = DATE(2023,08,31)
VAR _ENR_DATE = EOMONTH(_Max_Date,-2)+1

Filter( table,([MIN_ENR] >= _ENR_DATE && [MAX_ENR] <= _Max_Date))

 

 

I want to also select Max_ENR if it is > _Max_Date

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi NilR ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a tables.

    Table 2 = 
     var _Max_Date = DATE(2023,08,31)
    VAR _ENR_DATE = EOMONTH(_Max_Date,-2)+1
    return 
    Filter('Table', [max_enr]> _Max_Date)
    Table 3 = 
     var _Max_Date = DATE(2023,9,1)
    VAR _ENR_DATE = EOMONTH(_Max_Date,-3)+1
    return 
    Filter('Table', [max_enr] >= _ENR_DATE && [max_enr] <=_Max_Date)

    (3) Then the result is as follows.

     

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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

6 Replies

  • It seems like you want to select rows from a table where `MAX_ENR` is either between `_ENR_DATE` and `_Max_Date` or greater than `_Max_Date`. You can modify your DAX code to include this additional condition. Here's how you can do it:

    ```dax
    VAR _Max_Date = DATE(2023,08,31)
    VAR _ENR_DATE = EOMONTH(_Max_Date,-2)+1
    EVALUATE
    FILTER(
    table,
    ([MAX_ENR] >= _ENR_DATE && [MAX_ENR] <= _Max_Date) || [MAX_ENR] > _Max_Date
    )
    ```

    In this code, the `FILTER` function is used to select rows from the `table` where `MAX_ENR` is either between `_ENR_DATE` and `_Max_Date` or greater than `_Max_Date`. The `||` operator represents logical OR in DAX¹. This should give you the desired output. Let me know if you need further assistance! 😊

    • NilR's avatar
      NilR
      Post Patron

      your answer is correct and This is exactly what I need , but the result is not what I want. 

    • NilR's avatar
      NilR
      Post Patron

      parry2k 

      Select Members who have been active in the latest two months.

  • NilR not the logic based on the DAX but what is your business logic? What you are trying to achieve?

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi NilR ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) My test data is the same as yours.

    (2) We can create a tables.

    Table 2 = 
     var _Max_Date = DATE(2023,08,31)
    VAR _ENR_DATE = EOMONTH(_Max_Date,-2)+1
    return 
    Filter('Table', [max_enr]> _Max_Date)
    Table 3 = 
     var _Max_Date = DATE(2023,9,1)
    VAR _ENR_DATE = EOMONTH(_Max_Date,-3)+1
    return 
    Filter('Table', [max_enr] >= _ENR_DATE && [max_enr] <=_Max_Date)

    (3) Then the result is as follows.

     

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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