Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Display current month and last month by using "IF Statement"

i want to display data Current month and last month ,by using cal.month/yeat after two years month data  will be like 2021/01,2021,02.....2022/01,2022,02

Mahamood218_0-1637217130562.png  , 

But data should be(Month) like below but i write code it is not working

Mahamood218_2-1637218986565.png

 

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous,

Did you mean the formula would calculate based on the last date in your table instead of dynamic system date? If that is the case, you can add a variable to extract the 'last date' and use it as a condition to calculate in the if statement.

Month Tag =
VAR _lastDate =
    MAXX ( Table, [Date] )
RETURN
    IF (
        EOMONTH ( [Date], 0 ) = EOMONTH ( _lastDate, -1 ),
        "Last Month",
        IF (
            EOMONTH ( [Date], 0 ) = EOMONTH ( _lastDate, 0 ),
            "Current Month",
            FORMAT ( _lastDate, "YYYY/MM" )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , Create a new column like

 

Month Type = Switch( True(),
eomonth([Date],0) = eomonth(Today(),-1),"Last Month" ,
eomonth([Date],0)= eomonth(Today(),0),"Current Month" ,
Format([Date],"YYYY/MM")
)

Anonymous
Not applicable

Hi amitchandak,

Thanks for your supporting as per requirement coding is working 

Mahamood218_0-1637236605698.png

but as per my requirement i want display current month and last mont for ex. i have a data in my table i will see report after one year so then at that time my new filed sholud show the current month(01/2022,02/2022) and last month (11/2021,12/2021) like below pic

Mahamood218_1-1637236879310.png

means cal.year/month data is like below

01/2020

02/2021

our new table after write coding (after one year table data should like below)

2021/01(last month)

2021/02

2022/01(Current month)

2022/01

Hi @Anonymous,

Did you mean the formula would calculate based on the last date in your table instead of dynamic system date? If that is the case, you can add a variable to extract the 'last date' and use it as a condition to calculate in the if statement.

Month Tag =
VAR _lastDate =
    MAXX ( Table, [Date] )
RETURN
    IF (
        EOMONTH ( [Date], 0 ) = EOMONTH ( _lastDate, -1 ),
        "Last Month",
        IF (
            EOMONTH ( [Date], 0 ) = EOMONTH ( _lastDate, 0 ),
            "Current Month",
            FORMAT ( _lastDate, "YYYY/MM" )
        )
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.