Forum Discussion
Using SelectedValue in measure for computing volume
Hello,
Need help in setting up a measure that counts the number of rows that have a date that is selected in a slicer.
I used these measures:
SelectedDate = selectedvalue('Complaints Raw Data'[Date Received]) //to store the date selected in the measure
The fix is to move the SELECTEDVALUE inside the measure using a VAR:
Volume = VAR _SelectedDate = SELECTEDVALUE ( 'Complaints Raw Data'[Date Received] ) RETURN CALCULATE ( COUNT ( 'Complaints Raw Data'[short_id] ), 'Complaints Raw Data'[Date Received] = _SelectedDate )Hi,
Create a Calendar table and have a *:1 relationship from the Date received column to the Calendar table. To your slicer, drag the Date from the Calendar table. Write this measure
Volume = count('Complaints Raw Data'[short_id])
Hope this helps.
7 Replies
- grazitti_sapnaSuper User
Hi rogelep,
Try below DAX
Volume = VAR SelectedDt = SELECTEDVALUE( 'Complaints Raw Data'[Date Received] ) RETURN CALCULATE( COUNT('Complaints Raw Data'[short_id]), FILTER( ALL('Complaints Raw Data'), 'Complaints Raw Data'[Date Received] = SelectedDt ) )OR
Volume = VAR SelectedDt = SELECTEDVALUE( 'Complaints Raw Data'[Date Received] ) RETURN CALCULATE( COUNT('Complaints Raw Data'[short_id]), TREATAS( {SelectedDt}, 'Complaints Raw Data'[Date Received] ) )๐ I hope this solution helps you unlock your Power BI potential! If you found it helpful, click 'Mark as Solution' to guide others toward the answers they need.
๐ก Love the effort? Drop the kudos! Your appreciation fuels community spirit and innovation.
๐ As a proud SuperUser and Microsoft Partner, weโre here to empower your data journey and the Power BI Community at large.
๐ Curious to explore more? [Discover here].
Letโs keep building smarter solutions together! - Rahul_VyasRegular Visitor
Hi,
The error occurs because CALCULATE's filter arguments must be Boolean column expressions or table expressions โ you cannot directly reference a measure (like [SelectedDate]) inside a filter predicate. DAX doesn't allow Column = Measure as a direct filter argument.
Volume =
CALCULATE(
COUNT('Complaints Raw Data'[short_id]),
FILTER(
'Complaints Raw Data',
'Complaints Raw Data'[Date Received] = [SelectedDate]
)
)
====
FILTER() returns a table, which CALCULATE accepts. Inside FILTER, the row-by-row evaluation resolves the measure correctly.Hope this gets you moving in the right direction! If it solved your problem, hitting 'Mark as Solution' helps others find the answer faster. Kudos are always appreciated too โ they go a long way in keeping this community thriving.
I'm always happy to help. Don't hesitate to reach out if you have more questions!
- cengizhanarslanSuper User
The fix is to move the SELECTEDVALUE inside the measure using a VAR:
Volume = VAR _SelectedDate = SELECTEDVALUE ( 'Complaints Raw Data'[Date Received] ) RETURN CALCULATE ( COUNT ( 'Complaints Raw Data'[short_id] ), 'Complaints Raw Data'[Date Received] = _SelectedDate ) - Ashish_MathurSuper User
Hi,
Create a Calendar table and have a *:1 relationship from the Date received column to the Calendar table. To your slicer, drag the Date from the Calendar table. Write this measure
Volume = count('Complaints Raw Data'[short_id])
Hope this helps.
- v-echaithraCommunity Support
Hi rogelep ,
Thank you Ashish_Mathur , cengizhanarslan , danextian , grazitti_sapna for your inputs.
Weโd like to follow up regarding the recent concern. Kindly confirm whether the issue has been resolved, or if further assistance is still required. We are available to support you and are committed to helping you reach a resolution.
Thank you. - v-echaithraCommunity Support
Hi rogelep ,
May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.
Thank you.