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
erikboderek
Regular Visitor

Filter by Year into a Date Field

Hi Everybody,

I'm trying to build a measure which filters out values based on a year and retrieve the previous year. For example, if it's 2017, retrieve all 2016 fields. The problem I believe is with the filter. The Year field is a YYYY and the field Date is a M/D/YYYY hh:mm:ss. How do I get around this? Right now I am only retrieving a blank value. Here's my formula.

 

Current Year STLY =
var this_year = if(hasonevalue(Booking[Year]),
values(Booking[Year]), 2017)

var last_year = this_year - 1

var returnValue =
calculate(sum(Booking[Gross_Amount]),
filter (Booking, Booking[Date] = last_year &&
Booking[Year] = last_year)
)

return returnValue

4 REPLIES 4
v-jiascu-msft
Employee
Employee

Hi @erikboderek,

 

Could you please mark the proper answer as solution or share the answer if it's convenient for you? That will be a help to the others.

 

Best Regards!
Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
Super User

Hey,

 

I would just build a separate Calendar table, join the date column from this table with your table, so that do not have to consider the year column in your booking com.

 

Then it will become much more simpler to build your previous year measures. Maybe this gets you started:

 

http://www.daxpatterns.com/time-patterns/

 

Hope this helps



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

I do have a calendar table and there is a relationship between that table and my Booking table, though not to that fields mentioned in my post. If I were to add a relationship between from calendar table to my year, and/or date field, what would this measure then look like?

The simplest form would be

 

CALCULATE(SUM('ResellerSales_USD'[SalesAmount_USD]), SAMEPERIODLASTYEAR('Calendar'[DateKey]))

But this makes it necessary that DateKey column from the Calendar table is related (and the relationship is active) with the Date column from your bookings table.

 

If it's not possible to join the columns I guess you have to go through the link from daxpatterns I mentioned above, almost everything is treated there.

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.