Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

DAX

To get Previous month and current month as a new field.

 

Hi Guyz

 

I'm trying to create a custom column having "Current month" and "Previous month" as a tag based on the system date. 
For example:- ( my system date is 27-06-2020 )

CategoryDateAmount
A01-04-2020100
B01-04-2020100
C01-05-2020100
D02-05-2020100
E03-05-2020100
F04-05-2020100
G01-06-2020100
H02-06-2020100
I03-06-2020100
J04-06-2020100

 

Expected result::-

CategoryDateAmountFlag 
C01-05-2020100Previous month 
D02-05-2020100Previous month 
E03-05-2020100Previous month 
F04-05-2020100Previous month 
G01-06-2020100Current month 
H02-06-2020100Current month 
I03-06-2020100Current month 
J04-06-2020100Current month 
  • parry2k's avatar
    parry2k
    6 years ago

    Anonymous try this

     

    Tag =
    IF ( EOMONTH ( Table[Date], 0 ) = EOMONTH ( TODAY(), -1 ), "Previous Month",
    IF ( EOMONTH ( Table[Date], 0 ) = EOMONTH ( TODAY(), 0 ), "Current Month",
    ""
    ) )

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

4 Replies

  • Anonymous try this

     

     

    Tag =
    IF ( Table[Date] < EOMONTH ( TODAY(), -1 ) + 1, "Previous Month",
    IF ( EOMONTH ( Table[Date], 0 ) = EOMONTH ( TODAY(), 0 ), "Current Month",
    "Next Month"
    ) )
    

     

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Buddy, Thanks  a ton ! 

      I implemented the expression. However, April month is getting tagged as the previous month ( ideally it should not ).
      Technically, April as Not consider  ; May as Previous month and June as Current month 
      Please advise. 

       
      • parry2k's avatar
        parry2k
        Super User

        Anonymous try this

         

        Tag =
        IF ( EOMONTH ( Table[Date], 0 ) = EOMONTH ( TODAY(), -1 ), "Previous Month",
        IF ( EOMONTH ( Table[Date], 0 ) = EOMONTH ( TODAY(), 0 ), "Current Month",
        ""
        ) )

         

        I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

        Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

  • Icey's avatar
    Icey
    Community Support

    Hi Anonymous ,

     

    Is this problem solved?


    If it is solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.


    If not, please let me know.

     


    Best Regards,
    Icey