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

Filter last one year to till date

Hi Team, I have an requirement to filter the data for previous year(12 months)+ current year (till the date). Basically i want display total completed count in my table every month wise and always it should be display full year(2021)+ current date(till date) when i filter this on my visual level then it should filtering the data. so please let me know how can i achieve this.

1 ACCEPTED SOLUTION

Hi @sreddy47652 ,

 

Please try the measure.

 

 

flag = 
VAR CurYear =
    YEAR ( TODAY () )
RETURN
    IF ( YEAR ( MAX ( 'Table'[Date] ) ) IN { CurYear, CurYear - 1 }, 1, 0 )

vkkfmsft_0-1652339195673.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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

4 REPLIES 4
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below, and I hope the below measure helps to create suitable measure for your data model.

 

Slide1.jpg

 

Expected result measure: = 
VAR _condition =
    CALCULATE ( SUM ( Data[Value] ), PARALLELPERIOD ( 'Calendar'[Date], -1, YEAR ) )
        && SUM ( Data[Value] )
RETURN
    IF (
        _condition,
        CALCULATE ( SUM ( Data[Value] ), DATESYTD ( 'Calendar'[Date] ) )
            + CALCULATE ( SUM ( Data[Value] ), PARALLELPERIOD ( 'Calendar'[Date], -1, YEAR ) )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


@Jihwan_Kim , Thanks for your time and do the above one. My requirement is same but i need some flag value(1,0) based on that i can filter out current year and previous year becacuse already i have calucaltions for previous year and last year but when we have lot of years on my date column i want to display always previous year(12 months)+till date. when we have some kind of flag value i can filter out on visual level.

Hi @sreddy47652 ,

 

Please try the measure.

 

 

flag = 
VAR CurYear =
    YEAR ( TODAY () )
RETURN
    IF ( YEAR ( MAX ( 'Table'[Date] ) ) IN { CurYear, CurYear - 1 }, 1, 0 )

vkkfmsft_0-1652339195673.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@sreddy47652 , If date is selected

YTD= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Year]>=max('Date'[Year])-1  && 'Date'[Year]<=max('Date'[Year])  && 'Date'[Day of Year] <= Max('Date'[Day of Year]) ))

 

column

Day of Year =datediff([Year Start date] , [Date],Day) +1

 

Using today 

 


YTD Today=
var _min = date(year(today())-1 ,1,1)
var _day = today()
return
CALCULATE(sum('Table'[Qty]), FILTER(('Date'),'Date'[Date] >=_min && 'Date'[Date] <= _day) )

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.