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
AndreaPRJ
Helper I
Helper I

Calculate sales for all years prior to the selected year

Hello everyone.

I would like to calculate sales for all years prior to the selected year in a filter with the year field from the calendar table.(including the year itself). 

If I write the measure in this way it works (for example for all sales prior 2023)

Rolling All 1 =
    CALCULATE (
           SUM(Sales[Amount[) ,
          FILTER (
              Sales,
              Sales[Year] <= 2022))

 

But if i Try to dynamically pass year selected from the user by the filter, it does not work and show me only 2022 sales

Rolling All 2=

var YearSelected= SELECTEDVALUE(Calendar[Year] )

RETURN
    CALCULATE (
          SUM(Sales[Amount[) ,
          FILTER (
              Sales,
              Sales[Year] <= YearSelected))

 

What is the way to pass a value selected by a filter to a measure? (in this case filter linked to the calendar and specifically to the year)

 

Thank you very much

 

1 ACCEPTED SOLUTION
AndreaPRJ
Helper I
Helper I

Sorry, I solved with this code:

Rolling All =
 
Var YearSelected = SELECTEDVALUE(CALENDAR[YEAR])
RETURN
CALCULATE (
    [TotalSales] ,
    CALENDAR[YEAR]<=  YearSelected
    )

View solution in original post

2 REPLIES 2
AndreaPRJ
Helper I
Helper I

Sorry, I solved with this code:

Rolling All =
 
Var YearSelected = SELECTEDVALUE(CALENDAR[YEAR])
RETURN
CALCULATE (
    [TotalSales] ,
    CALENDAR[YEAR]<=  YearSelected
    )
johnt75
Super User
Super User

Try

Rolling All 2 =
VAR YearSelected =
    SELECTEDVALUE ( Calendar[Year] )
RETURN
    CALCULATE (
        SUM ( Sales[Amount] ),
        'Calendar'[Year] <= YearSelected,
        REMOVEFILTERS ( 'Calendar' )
    )

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors