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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
UKFan12
Frequent Visitor

Trying to pull data from Current Year and Year ago using Date Column

Hello There,

I have product images of ads at a YYYY-MM-DD level, and I am trying to use the date column filter to select a week such as "6/11/2023" but then have the option of filtering between "Current Year" and "Year Ago".

Product ImageDate
http://productimage1.com6/11/2023
http://productimage2.com6/11/2023
http://productimage3.com6/12/2022
http://productimage4.com6/12/2022
http://productimage5.com6/12/2022

 

The purpose of this is to have 2 image grids. The top will show the "Product Image" from the Ads for the current year filtered to date "6/11/2023" and the bottom image grid will show the "Product Images" from the same week year ago.

UKFan12_0-1692372194256.png


Here is the same link to a sample of my excel data. I am stumped! Any help is appreciated!

Power BI Using Current Year and Year Ago.xlsx

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

Hi @UKFan12 ,

 

Here's my solution.

You can create a calendar table for filtering date and create two measures for filtering images.

Calendar Table:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2023,6,1),DATE(2023,6,30)),"WeekNum",WEEKNUM([Date],2),"Year",YEAR([Date]))

Note that there's no relationship between tables.

vstephenmsft_0-1692672894388.png

 

Two measures:

Current Year Filter = IF(MAX('Table'[Date])=SELECTEDVALUE('Calendar'[Date]),1)
Year Ago Filter = 
var _day1=MAX('Table'[Date])
var _weeknum1=WEEKNUM(_day1,2)
var _year1=YEAR(_day1)
var _day2=MAX('Calendar'[Date])
var _weeknum2=WEEKNUM(_day2,2)
var _year2=YEAR(_day2)
return IF(_weeknum1=_weeknum2&&_year1=_year2-1,1)

Put Current Year Filter measure into visual-level filter of the visual called Current Year and put Year Ago Filter measure into visual-level filter of the visual called Year Ago. Both set up show items when the value is 1.

31.png32.png

Create a slicer with dates from the calendar. When you filter date such as "6/11/2023", below is the result.

vstephenmsft_1-1692673219627.png

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @UKFan12 ,

 

Here's my solution.

You can create a calendar table for filtering date and create two measures for filtering images.

Calendar Table:

Calendar = ADDCOLUMNS(CALENDAR(DATE(2023,6,1),DATE(2023,6,30)),"WeekNum",WEEKNUM([Date],2),"Year",YEAR([Date]))

Note that there's no relationship between tables.

vstephenmsft_0-1692672894388.png

 

Two measures:

Current Year Filter = IF(MAX('Table'[Date])=SELECTEDVALUE('Calendar'[Date]),1)
Year Ago Filter = 
var _day1=MAX('Table'[Date])
var _weeknum1=WEEKNUM(_day1,2)
var _year1=YEAR(_day1)
var _day2=MAX('Calendar'[Date])
var _weeknum2=WEEKNUM(_day2,2)
var _year2=YEAR(_day2)
return IF(_weeknum1=_weeknum2&&_year1=_year2-1,1)

Put Current Year Filter measure into visual-level filter of the visual called Current Year and put Year Ago Filter measure into visual-level filter of the visual called Year Ago. Both set up show items when the value is 1.

31.png32.png

Create a slicer with dates from the calendar. When you filter date such as "6/11/2023", below is the result.

vstephenmsft_1-1692673219627.png

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

Ritaf1983
Super User
Super User

Hi @UKFan12 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.