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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
VitorXavierCell
Regular Visitor

Accumulated graphic with annual comparison

Hello, 

 

I created two measures for my accumulated graphic that today is showing 2022x2021, one measure is calculating the sum of 2022 and the other is calculating the sum of 2021.

 

I need to improve the measure to use the filter of the year to change the comparison for 2023x2022, but without losing the previous view. I want to use a measure that I can use only de filter of the year and get the comparison of the filtered year with the previous year.

 

Follow the example below:

Accumulated example.PNG

 

Thanks in advance

1 ACCEPTED SOLUTION
Anonymous
Not applicable

For the current year

 

Accumulated Packs =

CALCULATE(SUM(FactTable[MeasureName]))

 

For the previous year:

Accumulated Packs Previous Year =

CALCULATE(SUM(FactTable[MeasureName]) , PREVIOUSYEAR('DimCalendar'[DateKey]))

 

Alternate

 

Accumulated Packs Previous Year =

CALCULATE(SUM(FactTable[MeasureName]) , SAMEPERIODLASTYEAR('DimCalendar'[DateKey]))

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

Hi @VitorXavierCell 
Please refr to attached sample file. I hope it will help you find the workable solution for your case.

1.png

Sales Amount = SUMX ( Sales, Sales[Quantity] * Sales[Net Price] )
Sales Amount RT = 
CALCULATE ( 
    [Sales Amount],
    'Date'[Date] <= MAX ( 'Date'[Date] )
)
Sales Amount RT Selected Year = 
VAR SelectedYear = MAX ( Years[Year] ) 
VAR StartDate =
    CALCULATE ( 
        MIN ( 'Date'[Date] ),
        'Date'[Year] = SelectedYear,
        ALL ( 'Date' )
    )
RETURN
    CALCULATE ( 
        [Sales Amount RT],
        'Date'[Year] = SelectedYear,
        Sales[Order Date] >= StartDate
    )
Sales Amount RT Previous Year = 
VAR SelectedYear = MAX ( Years[Year] ) 
VAR StartDate =
    CALCULATE ( 
        MIN ( 'Date'[Date] ),
        'Date'[Year] = SelectedYear - 1,
        ALL ( 'Date' )
    )
RETURN
    CALCULATE ( 
        [Sales Amount RT],
        'Date'[Year] = SelectedYear - 1,
        Sales[Order Date] >= StartDate
    )
Anonymous
Not applicable

Are you hardcoding the Year filter in the Measures?

 

If yes, then just remove the year filter and then you can use just 1 measure and then in the Visual, throw Year as a Legend.

 

Hello @Anonymous 

 

Thank you for your answer!

Your solution works in a good way, but I'd like to know if it's possible when I filter the year 2022 it shows the 2022 x 2021, and when I select the year 2023 it shows the comparison 2023x2022 in the graphic. Is that possible?

Thanks a lot

Anonymous
Not applicable

For the current year

 

Accumulated Packs =

CALCULATE(SUM(FactTable[MeasureName]))

 

For the previous year:

Accumulated Packs Previous Year =

CALCULATE(SUM(FactTable[MeasureName]) , PREVIOUSYEAR('DimCalendar'[DateKey]))

 

Alternate

 

Accumulated Packs Previous Year =

CALCULATE(SUM(FactTable[MeasureName]) , SAMEPERIODLASTYEAR('DimCalendar'[DateKey]))

Anonymous
Not applicable

Sure, create a new measure referencing old measure with Sameperiodlastyear filter. Then select it in the Values.

 

please mark my answer as a solution if it worked.

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.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.