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

Measure which uses a dynamic date in the calculate

Hi All,

 

Sadly here once again.

I have to create a measure which, given a date by the user, checks if it is between two dates, and counts how many times it happens.
Herewith my thought process:
X = Date given by the user

Measure = CALCULATE(COUNTROWS('Table'), X >= 'Table'[First Date] && X <= 'Table'[Second Date])

 

Now, my problem is when i have to do - X = Date given by the user - since i have no idea how it could be done. Is there any way i can give the measure a parameter which is given by the user?
So something like, i put something in the report where the user can type, make a measure which takes that value and in my measure above i replace X with this new measure.

 

Thanks,

L

1 ACCEPTED SOLUTION
PC2790
Community Champion
Community Champion

Try:

 

Measure = 
var DateSelected = SelectedValue(Table[Date])

return

CALCULATE(COUNTROWS('Table'), Filter(DateSelected >= 'Table'[First Date] && DateSelected <= 'Table'[Second Date]))

View solution in original post

3 REPLIES 3
PC2790
Community Champion
Community Champion

Hey @qLollo ,

 

You can provide a slicer with all the permissible dates you want user to select.

And when the user selects the date, you can capture that information using

DateSelected = Selectedvalue(Table[Date])

Further you can use it in your calculation.

qLollo
Frequent Visitor

Hi @PC2790, thanks for replying.

What you suggested to get the selected date works fine.
The problem now is that when i replace the X with the measure [DateSelected] i get an error.

Which is: In a True/False expression, used as a table filter, a function 'PLACEHOLDER' has been used, this is not allowed
The measure now is

Measure = CALCULATE(COUNTROWS('Table'), [DateSelected] >= 'Table'[First Date] && [DateSelected] <= 'Table'[Second Date])
 
PC2790
Community Champion
Community Champion

Try:

 

Measure = 
var DateSelected = SelectedValue(Table[Date])

return

CALCULATE(COUNTROWS('Table'), Filter(DateSelected >= 'Table'[First Date] && DateSelected <= 'Table'[Second Date]))

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.