Forum Discussion

Rjesak's avatar
Rjesak
Helper I
5 years ago
Solved

filter OR with multiple options

I have a table that has receipt_date and closure_date and those are also broken into calendar years so I also have receipt_CY and closure_CY.

 

I created a measure for the current year - just YEAR(TODAY()) - called Current_CY.

 

I want to have a page showing "Current".

 

It should show all records where receipt_CY = current_CY or closure_CY = current_CY or where receipt_date is not null and closure_date is null.

 

I tried building a dax filter but I can't compare receipt_CY to current_CY because receipt_CY (or closure_CY) has different values (obviously).

 

So table is like:

Unique_seqreceipt_datereciept_cyclosure_dateclosure_cy
11/1/20202020  
23/1/202020201/1/20212021
3  1/1/20212021
44/1/202020206/1/20202020

 

In this example, the "current" page would include records 1,2, and 3.

 

I figure I need to build a measure that I can use to drop in the filter but I've not been successful at figuring it out.

 

I know this shouldn't be that complicated but I'm stuck.

  • Hi, Rjesak 

    Please check the below picture and the sample pbix file's link down below.

    Instead of having extra columns for a year in the fact table, try having a dim-calendar table like the below, and create a measure like below.

     

     

    Count Unique Seq =
    IF (
    ISFILTERED ( 'Calendar' ),
    CALCULATE (
    COUNTROWS ( data ),
    FILTER (
    data,
    AND (
    data[receipt_date] <= MAX ( 'Calendar'[Date] ),
    OR (
    data[closure_date] >= MIN ( 'Calendar'[Date] ),
    data[closure_date] = BLANK ()
    )
    )
    )
    )
    )

     

    https://www.dropbox.com/s/d26henlpvp41c87/rjesakv2.pbix?dl=0 

     

     

    Hi, My name is Jihwan Kim.

     

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

     

    Linkedin: https://www.linkedin.com/in/jihwankim1975/

5 Replies

  • Hi, Rjesak 

    Please check the below picture and the sample pbix file's link down below.

    Instead of having extra columns for a year in the fact table, try having a dim-calendar table like the below, and create a measure like below.

     

     

    Count Unique Seq =
    IF (
    ISFILTERED ( 'Calendar' ),
    CALCULATE (
    COUNTROWS ( data ),
    FILTER (
    data,
    AND (
    data[receipt_date] <= MAX ( 'Calendar'[Date] ),
    OR (
    data[closure_date] >= MIN ( 'Calendar'[Date] ),
    data[closure_date] = BLANK ()
    )
    )
    )
    )
    )

     

    https://www.dropbox.com/s/d26henlpvp41c87/rjesakv2.pbix?dl=0 

     

     

    Hi, My name is Jihwan Kim.

     

    If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

     

    Linkedin: https://www.linkedin.com/in/jihwankim1975/

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Rjesak ,

    Try the following formula:

    Measure = 
    var tab = 
        CALCULATETABLE(
            VALUES('Table'[Unique_seq]),
            FILTER(
                'Table',
                'Table'[reciept_cy] = [Current_CY] 
                || 'Table'[closure_cy] = [Current_CY] 
                || ( NOT(ISBLANK('Table'[receipt_date]))
                && NOT(ISBLANK('Table'[closure_date])) )
            )
        )
    return 
        COUNTROWS(
            INTERSECT(
                tab,
                VALUES('Table'[Unique_seq])
            )
        )

     

    Then filter the Unique_seq field in the visuals:

    • Filter type: Top N
    • Show items: Top 1
    • By value: Measure

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

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

    filter OR with multiple options.pbix51 KB
  • Rjesak , Not very clear. You need to have a common date table joined to both dates one join will be inactive.

    Assume receipt date join is active 

    Create measures like

     

    CALCULATE(Count(Table[Unique_seq]),DATESMTD('Date'[Date]))

     

     

    calculate( calculate( Count(Table[Unique_seq]),USERELATIONSHIP ('Table'2[Close Date], 'Date'[Date])),DATESMTD('Date'[Date]))

     

     

    refer

    https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

    https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in-power-bi

     

     

     

  • Sorry everyone, I'm killing myself on a project so I'm working through these one by one to determine which is going to be best. I apologize for the delay.

    • v-kkf-msft's avatar
      v-kkf-msft
      Community Support

      Hi Rjesak ,

       

      Does your problem have been solved? If it is solved, please mark a reply which is helpful to you.

       

      If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

       

      Best Regards,
      Winniz