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
E_K_
Helper II
Helper II

Try to calculate for X month this year and compare to x month last year in flexible way

Hi

 

I'm trying to create 2 columns that will show for example March 2022 vs March 2023 stats for a team when you filter on a specific month.

 

What I have at the moment is this (I have a 'Dates' table and the team specific stats is calculated from data in 'Incidents' throug a calculated measure). It doesn't work 🙂

 

MTTR specific month =
VAR StartDate = STARTOFMONTH('Dates'[Date])
VAR EndDate = ENDOFMONTH('Dates'[Date])
RETURN
CALCULATE([MTTR], DATESBETWEEN('Dates'[Date], StartDate, EndDate))
 
However when I filter for the use case, the matrix does not remove all the respective columns to just show January - is there something I need to do with the matrix or another measure for the months in the matrix to be flexible? At the moment it is just filtering on teams have have a stat for bth January 2022 & January 2023. The column on the far left is just a flat overall [MTTR] to compare with.
 
  E_K__0-1684427090277.png

 

 

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

Hi @E_K_ ,


Due to I don't know your data model, I will give you some suggestions. According to your statement, I think you only want to compare the data current month with the data on same period in pervious year.

Her I create a sample to have a test.

veqinmsft_0-1684738326670.png

Measure:

MTTR specific month =
VAR _currentyear =
    YEAR ( TODAY () )
VAR _selectmonth =
    SELECTEDVALUE ( DimMonth[Month] )
RETURN
    IF (
        ISFILTERED ( DimMonth[MonthName] ),
        CALCULATE (
            [MTTR],
            FILTER (
                'Calendar',
                'Calendar'[Year]
                    IN { _currentyear, _currentyear - 1 }
                    && 'Calendar'[Month] = _selectmonth
            )
        ),
        [MTTR]
    )

Result is as below.

veqinmsft_1-1684738450508.pngveqinmsft_2-1684738467629.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

1 REPLY 1
v-eqin-msft
Community Support
Community Support

Hi @E_K_ ,


Due to I don't know your data model, I will give you some suggestions. According to your statement, I think you only want to compare the data current month with the data on same period in pervious year.

Her I create a sample to have a test.

veqinmsft_0-1684738326670.png

Measure:

MTTR specific month =
VAR _currentyear =
    YEAR ( TODAY () )
VAR _selectmonth =
    SELECTEDVALUE ( DimMonth[Month] )
RETURN
    IF (
        ISFILTERED ( DimMonth[MonthName] ),
        CALCULATE (
            [MTTR],
            FILTER (
                'Calendar',
                'Calendar'[Year]
                    IN { _currentyear, _currentyear - 1 }
                    && 'Calendar'[Month] = _selectmonth
            )
        ),
        [MTTR]
    )

Result is as below.

veqinmsft_1-1684738450508.pngveqinmsft_2-1684738467629.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.

 

 

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.