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
dBrand
Frequent Visitor

Trying to replace a Date filter in a measure, based of the date filter

I have a Date table and a Fact Table. I have a Quarter and Year field in my Date table. I have a Filter on the page for the Quarter. I would like to calculate the total hours form the Fact table for the Year, based on the Quarter selected in the Filter. I try using:

Calulcate(Sum(fact[hours]), Date[Year]), but it always returns the hours for the Quarter? Not sure how to tell it to replace the Quarter filter with the Year, based onthe Quarter selected. Any help would be appreciated! Thanks you.

2 ACCEPTED SOLUTIONS

My Date table has a Quarter field in format 2020Q1, 2020Q2,...

the Year field is the 4-digit year. 

View solution in original post

I finally figured this out. Maybe htis will help others. Here is what I came up with (Sheet1 is the data set, Dates is my Date Table):

 

Total Amt for Year =
VAR HoldFilter = SELECTEDVALUE(Dates[Year Quarter])
VAR HoldYear = LEFT(HoldFilter, 4)
RETURN
CALCULATE(Sumx(Sheet1,Sheet1[Amt]),REMOVEFILTERS(Dates[Year Quarter]), Dates[Year]=Value(HoldYear))

View solution in original post

4 REPLIES 4
dBrand
Frequent Visitor

Could really use help. Still unable to make this work. Please. Thanks,

Greg_Deckler
Super User
Super User

@dBrand What does your data look like? Is your quarter field something like Q12021, Q22021 or just Q1, Q2, etc.?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

I finally figured this out. Maybe htis will help others. Here is what I came up with (Sheet1 is the data set, Dates is my Date Table):

 

Total Amt for Year =
VAR HoldFilter = SELECTEDVALUE(Dates[Year Quarter])
VAR HoldYear = LEFT(HoldFilter, 4)
RETURN
CALCULATE(Sumx(Sheet1,Sheet1[Amt]),REMOVEFILTERS(Dates[Year Quarter]), Dates[Year]=Value(HoldYear))

My Date table has a Quarter field in format 2020Q1, 2020Q2,...

the Year field is the 4-digit year. 

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.