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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Filter Formula with IF Statement

Hi all,

 

I'm trying to create a measure where I sum the total revenue field based on my Time Period filter (Month, Quarter, Year).  For the year, I need my measure to say that if it's not the current year then return the amounts for December only.  If it's the current year, then return last months amount (If it's August, show July).   I have a Month Number & Current Year column that hopefully helps.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I have built a data sample from 2019/1/1 to 2021/12/31 (I think  Month Number & Current Year may better split to Year and Month column)

Date-Year-Month-Value table.PNG

 

And according to your description, you need to create a new table for slicer like this:

ForSlicer = DISTINCT( SELECTCOLUMNS('Table',"Year",[Year],"Month",[Month]))

Year Month for slicer.PNG

Then create a measure and display it in Card visual:

Measure =
VAR _year =
    SELECTEDVALUE ( ForSlicer[Year] )
VAR _month =
    SELECTEDVALUE ( ForSlicer[Month] )
RETURN
    IF (
        _year <> YEAR ( TODAY () ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', 'Table'[Year] = _year && [Month] = 12 )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', [Year] = _year && 'Table'[Month] = _month - 1 )
        )
    )

 

Not current year.PNGCurrent year previous month.PNG

 

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

 

I have built a data sample from 2019/1/1 to 2021/12/31 (I think  Month Number & Current Year may better split to Year and Month column)

Date-Year-Month-Value table.PNG

 

And according to your description, you need to create a new table for slicer like this:

ForSlicer = DISTINCT( SELECTCOLUMNS('Table',"Year",[Year],"Month",[Month]))

Year Month for slicer.PNG

Then create a measure and display it in Card visual:

Measure =
VAR _year =
    SELECTEDVALUE ( ForSlicer[Year] )
VAR _month =
    SELECTEDVALUE ( ForSlicer[Month] )
RETURN
    IF (
        _year <> YEAR ( TODAY () ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', 'Table'[Year] = _year && [Month] = 12 )
        ),
        CALCULATE (
            SUM ( 'Table'[Value] ),
            FILTER ( 'Table', [Year] = _year && 'Table'[Month] = _month - 1 )
        )
    )

 

Not current year.PNGCurrent year previous month.PNG

 

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

lbendlin
Super User
Super User

Please provide sample data in usable format (not as a picture - maybe insert into a table?) and show the expected outcome.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors