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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Syndicate_Admin
Administrator
Administrator

FILTER

Hello!

I have a table where I have a month number field and a year number field. I do segmentation with year number and month number. (There is no calendar table). I want to calculate the total sales for the segmented month, but also for the month before and after the selected month. What expression would the new measure have?

Thank you

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

I suggest you to add a YearMonth column in your data table and then create measures to achieve your goal.

Previous Month Value = 
VAR _PREVIOUS =
    CALCULATE (
        MAX ( 'Table'[YearMonth] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] < MAX ( 'Table'[YearMonth] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] = _PREVIOUS )
    )
Future Month Value = 
VAR _Future =
    CALCULATE (
        MIN ( 'Table'[YearMonth] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] > MAX ( 'Table'[YearMonth] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] = _Future )
    )

Result is as below.

vrzhoumsft_0-1682388483983.png

 

Best Regards,
Rico Zhou

 

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
v-rzhou-msft
Community Support
Community Support

Hi @Syndicate_Admin ,

 

I suggest you to add a YearMonth column in your data table and then create measures to achieve your goal.

Previous Month Value = 
VAR _PREVIOUS =
    CALCULATE (
        MAX ( 'Table'[YearMonth] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] < MAX ( 'Table'[YearMonth] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] = _PREVIOUS )
    )
Future Month Value = 
VAR _Future =
    CALCULATE (
        MIN ( 'Table'[YearMonth] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] > MAX ( 'Table'[YearMonth] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Value] ),
        FILTER ( ALL ( 'Table' ), 'Table'[YearMonth] = _Future )
    )

Result is as below.

vrzhoumsft_0-1682388483983.png

 

Best Regards,
Rico Zhou

 

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 add a calendar table to your data model.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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