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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
DAXRichArd
Resolver I
Resolver I

Time series comparative analysis, sum incorrect previous years, multiple slicer filters select v all

Hello,

I am sure this has been address.

I've hacked away at this forum but could not find the response.

Current Situaiton

  • Commercial aviation data.
  • Time intervals; data is monthly data.
  • Most current year is 11 months of the calendar year.
  • Objective: time series comparative analysis.
  • Time intelligence in use:
    • Filter calendar table using CALCULATE
    • DATEADD
    • DATESBETWEEN
      PREVIOUSMONTH
    • TOTALYTD
    • SAMEPERIODLASTYEAR
Output results to a table (see pics attached).
Output is a monthly time series with aggregations for year to date.
Complicating Factor
  •  For previous years, I include in my measure 
IF (
            ISBLANK ( [summed numerical column] ),
            BLANK (),
  • That way only data for the months of the most current year are displayed.
    • e.g. if this year I only have 11 months of data (Jan - Nov) previous years will also only dispay 11 months of data.
 

Problem

  • If my slicer is set to all months, previous years show 11 months but total 12 months.
  • I want previous years to follow the current year and total for the months shown.
  • e.g. if my current year has 11 months, all time series totals (this year, last year, 2 years ago, year 2019....) to only the 11 months being displayed.

Thx in advance for all your help.

 

DAXRichArd_0-1673030439235.png

DAXRichArd_1-1673030506512.png

 

1 REPLY 1
sturlaws
Resident Rockstar
Resident Rockstar

Hi,

this is one way of solving your issue, although sligthly verbose:

MeasureCurrentYear cumulative =
VAR _year =
    CALCULATE ( SELECTEDVALUE ( Dates[Year] ) )
VAR _month =
    CALCULATE ( SELECTEDVALUE ( Dates[MonthNum] ) )
VAR _maxMonthCurrentYear =
    CALCULATE (
        MAX ( 'Table'[month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Year] = _year )
    )
RETURN
    IF (
        _month <= _maxMonthCurrentYear
            && HASONEVALUE ( Dates[Month] ),
        CALCULATE (
            SUM ( 'Table'[NumberOfPassengers] ),
            FILTER ( ALL ( Dates ), Dates[Year] = _year && Dates[MonthNum] <= _month )
        ),
        IF (
            NOT ( HASONEVALUE ( Dates[Month] ) ),
            SUMX (
                CALCULATETABLE (
                    'Table',
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Year] = _year
                            && 'Table'[month] <= _maxMonthCurrentYear
                    )
                ),
                'Table'[NumberOfPassengers]
            ),
            BLANK ()
        )
    )

 

MeasureCurrentYear-1 cumulative =
VAR _year =
    CALCULATE ( SELECTEDVALUE ( Dates[Year] ) )
VAR _month =
    CALCULATE ( SELECTEDVALUE ( Dates[MonthNum] ) )
VAR _maxMonthCurrentYear =
    CALCULATE (
        MAX ( 'Table'[month] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Year] = _year )
    )
RETURN
    IF (
        _month <= _maxMonthCurrentYear
            && HASONEVALUE ( Dates[Month] ),
        CALCULATE (
            SUM ( 'Table'[NumberOfPassengers] ),
            FILTER ( ALL ( Dates ), Dates[Year] = _year - 1 && Dates[MonthNum] <= _month )
        ),
        IF (
            NOT ( HASONEVALUE ( Dates[Month] ) ),
            SUMX (
                CALCULATETABLE (
                    'Table',
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[Year] = _year - 1
                            && 'Table'[month] <= _maxMonthCurrentYear
                    )
                ),
                'Table'[NumberOfPassengers]
            ),
            BLANK ()
        )
    )

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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