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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Use measure as a filter in DAX

Hi,

 

I have a dax which should return a date. I want it to get filtered by a measure value.

68 in the dax needs to be replaced by a measure. The moment I put the measure there, it returns BLANK. And when it's hard coded to a value, it returns correct result. Any help here would be highly appreciated. Thank You.

Start of previous quarter =
CALCULATE(DISTINCT(Mytable[QTR_START_DATE]),
CALCULATETABLE(ALL(Mytable)),
(Mytable[QTR_SEQ_NUMBER]= 68))
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@Anonymous Try this and then you can more easily troubleshoot what is going wrong by returning the variables (use TOCSV for the table variables).

Measure = 
  VAR __FilterMeasure = [FilterMeasure]
  VAR __Table = FILTER(ALL('MyTable'), [QTR_SEQ_NUMBER] = __FilterMeasure)
  VAR __Dates = DISTINCT(SELECTCOLUMNS(__Table, "__Date", [QTR_START_DATE]))
  VAR __Result = MAXX(__Dates, [__Date])
RETURN
  __Result

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
Greg_Deckler
Community Champion
Community Champion

@Anonymous Try this and then you can more easily troubleshoot what is going wrong by returning the variables (use TOCSV for the table variables).

Measure = 
  VAR __FilterMeasure = [FilterMeasure]
  VAR __Table = FILTER(ALL('MyTable'), [QTR_SEQ_NUMBER] = __FilterMeasure)
  VAR __Dates = DISTINCT(SELECTCOLUMNS(__Table, "__Date", [QTR_START_DATE]))
  VAR __Result = MAXX(__Dates, [__Date])
RETURN
  __Result

 



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

I was not putting the variables in the right way. This method worked. Thanks a lot Greg. Saved my day.

Anonymous
Not applicable

Thanks Greg. I did try this and it's also returning a date but not correct. I'll give some more details here. My dataset has multiple rows with period and quarter information. I need to find Quarter to Quarter Sales, which means I need Current quarter start date, current quarter end date, previous quarter end date and previous quarter start date. Previous Quarter Start date is the trickiest because user can select multiple periods. Attaching the date format in the table. So if someone selects qtr 202303 and 202302 - then previous quarter start date should be 10/9/2022. The DAX needs to return this date.

PERIODYR_QTRQTR_START_DATEQTR_END_DATEPREV_QTR_START_DATEPREV_QTR_END_DATE
2023102023037/16/202310/7/20234/23/20237/15/2023
2023092023037/16/202310/7/20234/23/20237/15/2023
2023082023037/16/202310/7/20234/23/20237/15/2023
2023072023024/23/20237/15/20231/1/20234/22/2023
2023062023024/23/20237/15/20231/1/20234/22/2023
2023052023024/23/20237/15/20231/1/20234/22/2023
2023042023011/1/20234/22/202310/9/202212/31/2022
2023032023011/1/20234/22/202310/9/202212/31/2022
2023022023011/1/20234/22/202310/9/202212/31/2022
2023012023011/1/20234/22/202310/9/202212/31/2022
20221320220410/9/202212/31/20227/17/202210/8/2022
20221220220410/9/202212/31/20227/17/202210/8/2022
20221120220410/9/202212/31/20227/17/202210/8/2022
2022102022037/17/202210/8/20224/24/20227/16/2022
2022092022037/17/202210/8/20224/24/20227/16/2022
2022082022037/17/202210/8/20224/24/20227/16/2022
2022072022024/24/20227/16/20221/2/20224/23/2022
2022062022024/24/20227/16/20221/2/20224/23/2022
2022052022024/24/20227/16/20221/2/20224/23/2022
      
Anonymous
Not applicable

smathur12_1-1697811070767.png

 

 

The format of the table in my previous message did not come proper. Here is a snapshot for your reference.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors