Forum Discussion

admin11's avatar
admin11
Icon for Memorable Member rankMemorable Member
4 years ago
Solved

How to combine 2 expression into 1 ?

Hi All

 

I have below 2 seperate expression :-

 

Show Last 3 Yr = IF ('DATE'[Year] >= Year(TODAY()) - 3, 1, 0)
Show Last 4 Yr = IF ('DATE'[Year] >= Year(TODAY()) - 4, 1, 0)
 
May i know how to combine both of them into 1 , look some thing like below :-
 
Show Last 3 or 4 Yr =
IF ('DATE'[Year] >= Year(TODAY()) - 3, 3, 0)
IF ('DATE'[Year] >= Year(TODAY()) - 4, 4, 0)
 
So that i can on fly change from 3 to 4 year filter
 
Paul
  • That's because it needs to be defined as a new calculated table, not a measure or calculated column. See the example I attached previously.

14 Replies

  • Hi   admin11 

    Try this:

     

     

    Show Last 3 or 4 Yr =
    VAR _Y3 =
        'DATE'[Year]
            >= YEAR ( TODAY () ) - 3
    VAR _Y4 =
        'DATE'[Year]
            >= YEAR ( TODAY () ) - 4
    RETURN
        IF ( 'DATE'[Year] >= _Y3, 3, IF ( 'DATE'[Year] = _Y4, 4, 0 ) )

     

     

    it will return 3 for the first 3 years and 4 for a year before that.

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
    Appreciate your Kudos!!
    LinkedIn: www.linkedin.com/in/vahid-dm/

     

     

      • VahidDM's avatar
        VahidDM
        Icon for Super User rankSuper User

        admin11 

        My bad.

         

        Try this:

        Show Last 3 or 4 Yr =
        VAR _Y3 =
            YEAR ( TODAY () ) - 3
        VAR _Y4 =
            YEAR ( TODAY () ) - 4
        RETURN
            IF ( 'DATE'[Year] >= _Y3, 3, IF ( 'DATE'[Year] = _Y4, 4, 0 ) )

         

         

        If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
        Appreciate your Kudos!!
        LinkedIn: 
        www.linkedin.com/in/vahid-dm/