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

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
Super User
Super User

@smathur12 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

 


@ 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...

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@smathur12 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

 


@ 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 was not putting the variables in the right way. This method worked. Thanks a lot Greg. Saved my day.

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
      

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
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.