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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

DAX calculate if datedif between slicer selected date and column date equal to value

I'm making calculated buckets based on the date difference. Currently, the bucket is generated based on the last date of the current month as below measure.

 

Measure =CALCULATE(SUM(RF[Cost]),DATEDIFF(EOMONTH(TODAY(),0),RF[PoDate],DAY)<30)
 
Basically this gives sum of the cost if the count of the dates between the current month end date and podate lesser than 30. But i need EOMONTH(TODAY(),0) to be replaced with a user-selected value using a slicer or any other method. 
 
Additionally, I have created 
Parameter = GENERATESERIES(DATE(2021,01,01),DATE(2023,01,01), 1)
Parameter Value = SELECTEDVALUE('Parameter'[Parameter])
where user to select the date using slicer. But when i replace Parameter value with EOMONTH(TODAY(),0) like below
 
Measure = CALCULATE(SUM(BIItemLedgerRF[CostAmountActual]),DATEDIFF(MIN(Parameter[Parameter Value]),BIItemLedgerRF[PoDate.PoDate],DAY)<30)
 
But It generates an error by telling Column 'Parameter Value' in table 'Parameter' cannot be found or may not be used in this expression.
 
Please help me to sort this out struggling with this for a long time.
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , make sure the names are correct.

 

Also try like , You need have some grouping level for this. I assumed - BIItemLedgerRF[Bill ID]

Measure =
var _min =MINX(allselected(Parameter),Parameter [Parameter Value])
return
CALCULATE(SUM(BIItemLedgerRF[CostAmountActual]),filter(values(BIItemLedgerRF[Bill ID]) , DATEDIFF(_min,max(BIItemLedgerRF[PoDate.PoDate]),DAY)<30))

 

 

You need to get dynamic bucketing. Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

 

also refer date diff across table

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Difference-Across/ba-p/934397#M451

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

@Anonymous 

 

It can't be used in this expression because logical expressions under CALCULATE can't contain measures. They can only be of this form (more or less):

 

F(T[Col]) <operator> Value,

 

where Value is a constant and F is a function that depends only on one column in a base table, never measures.

 

Therefore, first capture the value of the measure in a variable and then use the variable in a well-formed expression. And you don't need any MIN around the parameter value. You should also follow Best Practices when formatting and writing DAX code. Otherwise, you'll get into trouble rather sooner than later.

 

Rules for DAX Code Formatting - SQLBI

Anonymous
Not applicable

@Anonymous  Found the solution from another user.  Till today I have not followed formating since I was transferred to DAX from M query very recently. Thank you for aware me of best practising on DAX code and for the reference. 

amitchandak
Super User
Super User

@Anonymous , make sure the names are correct.

 

Also try like , You need have some grouping level for this. I assumed - BIItemLedgerRF[Bill ID]

Measure =
var _min =MINX(allselected(Parameter),Parameter [Parameter Value])
return
CALCULATE(SUM(BIItemLedgerRF[CostAmountActual]),filter(values(BIItemLedgerRF[Bill ID]) , DATEDIFF(_min,max(BIItemLedgerRF[PoDate.PoDate]),DAY)<30))

 

 

You need to get dynamic bucketing. Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

 

also refer date diff across table

https://community.powerbi.com/t5/Community-Blog/Decoding-Direct-Query-in-Power-BI-Part-2-Date-Difference-Across/ba-p/934397#M451

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

The method you mentioned has worked. Additionally by following the references you mentioned, found this article https://www.credera.com/insights/creating-aging-report-using-a-user-selected-date-in-power-bi on how to handle bucketing.

 

Thank you @amitchandak 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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