Forum Discussion
Selectedvalue date between two dates
- Anonymous1 year ago
Hi ArchieEric
Please try the following Measure:Measure = IF(SELECTEDVALUE(CalendarTable[Date]) >= SELECTEDVALUE('Table'[Start]) && SELECTEDVALUE(CalendarTable[Date]) <= SELECTEDVALUE('Table'[End]) , 1 , 0)Count rows:
Count = CALCULATE(COUNTROWS('Table'),FILTER('Table',[Measure]=1))By using measure, you can dynamically calculate the total number of rows based on the different dates you choose.
Result:Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
9 Replies
- shafiz_pSuper User
Hi ArchieEric It looks like your DAX code isn’t returning the expected results because the SELECTEDVALUE function might not be working as intended without a relationship between the tables. You can try this code:
SelectedMasters = VAR selectedmonth = SELECTEDVALUE('Months'[Month Year]) RETURN IF ( NOT ISBLANK(selectedmonth) && 'ContinuousService'[ContractStart] <= selectedmonth && 'ContinuousService'[ContractEnd] >= selectedmonth, 1, 0 )It will return 0 if selectedmonth is blank. I would suggest try develop relationship using virtual relationship function TREATAS if possible.
Hope this helps!!If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz - ArchieEricFrequent Visitor
Im nut sure how i build a relationship between the two tables, the 'Months'[Month Year] field doesnt directly relate to any field in the 'ContinuousService' table
the 'Months'[Month Year] field is a date and i want to pick rows from the 'ContinuousService' table when the selected [Month Year] field is between the [ContractStart] field and the [ContractEnd] Field
- ArchieEricFrequent Visitor
Thanks a lot for the reply BTW
- AnonymousNot applicable
Hi ArchieEric
Based on your needs, I have created the following table.
CalendarTabe:(from 1/1/2010 to 10/29/2024)CalendarTable = CALENDAR(DATE(2010,1,1),DATE(2024,10,29))DateTable:
Then use the following Dax:
Measure = VAR _select_date = SELECTEDVALUE('Table'[Date]) VAR _max_date = MAX('CalendarTable'[Date]) VAR _min_date = MIN('CalendarTable'[Date]) RETURN IF(_select_date >= _min_date && _select_date <= _max_date ,1,0)If you choose date from 1/1/2010 to 10/29/2024
If you choose date from 1/26/2018 to 10/29/2024
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ArchieEricFrequent Visitor
I think I need a column rather than a measure
Id like a 4th column on the table to say whether the selected month is between the ContractStartMonth and ContractEndMonth and id like to assess it row by row
if there are 100 rows id like a card to say on 50 of them the selected month falls between the dates
- AnonymousNot applicable
Hi ArchieEric
Are you only considering the month, or do you need to take the year into account as well?
Please provide your sample data in a copyable format, rather than a screenshot.Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- AnonymousNot applicable
Hi ArchieEric
Please try the following Measure:Measure = IF(SELECTEDVALUE(CalendarTable[Date]) >= SELECTEDVALUE('Table'[Start]) && SELECTEDVALUE(CalendarTable[Date]) <= SELECTEDVALUE('Table'[End]) , 1 , 0)Count rows:
Count = CALCULATE(COUNTROWS('Table'),FILTER('Table',[Measure]=1))By using measure, you can dynamically calculate the total number of rows based on the different dates you choose.
Result:Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- ArchieEricFrequent Visitor
Excellent thank you
seemed to be the extra use of SELECTEDVALUE on the main table field that did it?