Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hey Guys, we have Table A (ID(Int), Name(String), Start Date(Date)), Table B (No of Days(Int)). We use slicer to select the ID and No of Days, it is maintained within the report but different page.
Functionality Required:
1. Select ID from [SelectedID] Slicer
2. Select No of days from [No of Days] Slicer
3. Capture the Start Date of selected ID
4. Calculate date range(For example we have selected 4 in the no of days slicer) it should display + and - of the start date based on no of days selection.
5. In the second page, Assume we have start date of the selected id is (11/14/2024) as per no of days selection it should display from 11/10/2024(-4 days) to 11/18/2024 (+4 days)
6. We tried by using DAX but it didn't work for us. Please find the DAX expression below.
Solved! Go to Solution.
Hi @GokulBALAJI
Late reply. Try this:
"SelectID Table"
SelectID Table =
SELECTCOLUMNS(
'Table A',
"SelectID",
'Table A'[ID],
"StartDate",
'Table A'[Start Date]
)
The code is modified as follows,
DateRangeFlag =
VAR SelectedDate = SELECTEDVALUE('SelectID Table'[StartDate])
VAR SelectedNumberOfDays = SELECTEDVALUE('Table B'[No of Days])
VAR DateRangeStart = SelectedDate - SelectedNumberOfDays
VAR DateRangeEnd = SelectedDate + SelectedNumberOfDays
VAR CurrentDate = MAX('Table A'[Start Date])
RETURN
IF(
ISFILTERED('SelectID Table'[SelectID])
&&
CurrentDate >= DateRangeStart
&&
CurrentDate <= DateRangeEnd,
1,
0
)
In "Filters", filter the measure and select the records where the measure is equal to "1".
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @GokulBALAJI
Thank you very much Bibiano_Geraldo and Kedar_Pande for your prompt reply.
I'm not sure if I'm understanding your thoughts correctly. Perhaps you need to output “Yes” only if the slicer is selected. If so, try the following:
”Table A“
"Table B"
"SelectID Table"
SelectID Table =
SELECTCOLUMNS(
'Table A',
"SelectID",
'Table A'[ID]
)
Create a measure.
DateRangeFlag =
VAR SelectedID = VALUES('SelectID Table'[SelectID])
VAR SelectedNumberOfDays = SELECTEDVALUE('Table B'[No of Days])
VAR SelectedStartDate =
CALCULATE(
MAX('Table A'[Start Date]),
'Table A'[ID] IN SelectedID
)
VAR DateRangeStart = SelectedStartDate - SelectedNumberOfDays
VAR DateRangeEnd = SelectedStartDate + SelectedNumberOfDays
VAR CurrentDate = MAX('Table A'[Start Date])
RETURN
IF(
ISFILTERED('SelectID Table'[SelectID])
&&
CurrentDate >= DateRangeStart
&&
CurrentDate <= DateRangeEnd,
"Yes",
"No"
)
Here is the result.
If you have any other questions, please let me know.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @v-nuoc-msft Thank you for your effort. But this isn't what i am expecting. my requirement is simple but missing something to achieve.
1. Select id
2. capture the date from the selected id
3. calculate number of days(+ & -) from the selected number of days in start date. Eg: start date = 05-01-2024. Date range should be 03-01-2024 to 07-01-2024 if the number of days (2) is selected.
4. the details table should show the records which falls in the above date range.
Please let me know if you need any other additional information on the requirement.
Hi @GokulBALAJI
Late reply. Try this:
"SelectID Table"
SelectID Table =
SELECTCOLUMNS(
'Table A',
"SelectID",
'Table A'[ID],
"StartDate",
'Table A'[Start Date]
)
The code is modified as follows,
DateRangeFlag =
VAR SelectedDate = SELECTEDVALUE('SelectID Table'[StartDate])
VAR SelectedNumberOfDays = SELECTEDVALUE('Table B'[No of Days])
VAR DateRangeStart = SelectedDate - SelectedNumberOfDays
VAR DateRangeEnd = SelectedDate + SelectedNumberOfDays
VAR CurrentDate = MAX('Table A'[Start Date])
RETURN
IF(
ISFILTERED('SelectID Table'[SelectID])
&&
CurrentDate >= DateRangeStart
&&
CurrentDate <= DateRangeEnd,
1,
0
)
In "Filters", filter the measure and select the records where the measure is equal to "1".
Here is the result.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @GokulBALAJI
Data type problem, please check the field mentioned in the error and change its data type.To resolve this, you can use the VALUE function to convert the text to a number or the FORMAT function to convert the number to text. For example:
DateRangeFlagObj = IF(VALUE(SELECTEDVALUE([YourMeasure])) = [YourNumberColumn], 1, 0)
Regards,
Nono Chen
i try to use the above expression. but i couln't find the measure if i give in the place of [Your Measure]. it shows parameter is not the correct type.
Hi @Bibiano_Geraldo and @Kedar_Pande I dont see much differences in the output. it is giving the 'Yes' value for daterangeflag. But it is showing 'Yes' for all the records. Expected output is to show only for the date range within the number of days selection. if that is happening then we can use daterangeflag as filter and keep the value as 'Yes'. May i know any other method apart from what i have mentioned. Thank you so much for your support and understanding.
Hi @GokulBALAJI ,
Let try a diferent way by the bellow DAX Code's:
First try this dateRangeFlag measure:
DateRangeFlag =
VAR selectedstartdate = [SelectedStartDate]
VAR days = [SelectedNumberofDays]
VAR startdate = selectedstartdate - days
VAR enddate = selectedstartdate + days
VAR selecteddate = MAXX(
FILTER('Table A', 'Table A'[ID] = [SelectedID]),
'Table A'[Start Date]
)
RETURN
IF(selecteddate >= startdate && selecteddate <= enddate, "Yes", "No")
In this updated DateRangeFlag measure, selecteddate is calculated using MAXX within the context of the selected ID, ensuring it only considers the start date for the selected ID.
Additionally, make sure that your visualizations or tables are filtered by the DateRangeFlag measure to only show records where the flag is “Yes”.
If above measure work, you can stop right here, if not please follow the steps bellow:
Considering that you have SelectedID and SelectedNumberofDays measures, now you can calculate Start and End Dates for the Range by this DAX:
DateRangeStart =
VAR selectedstartdate =
CALCULATE(
MAX('Table A'[Start Date]),
'Table A'[ID] = [SelectedID]
)
RETURN
selectedstartdate - [SelectedNumberofDays]
DateRangeEnd =
VAR selectedstartdate =
CALCULATE(
MAX('Table A'[Start Date]),
'Table A'[ID] = [SelectedID]
)
RETURN
selectedstartdate + [SelectedNumberofDays]
And now create the DateRangeFlag measure to return "Yes" only if a date in the dataset falls within the calculated start and end dates by this DAX:
DateRangeFlag =
VAR selectedstartdate = [SelectedStartDate]
VAR days = [SelectedNumberofDays]
VAR startdate = selectedstartdate - days
VAR enddate = selectedstartdate + days
RETURN
IF(
'Table A'[Start Date] >= startdate &&
'Table A'[Start Date] <= enddate,
"Yes",
"No"
)
Apply the DateRangeFlag as a Visual Level Filter: In your visual on the report page, set the DateRangeFlag field as a filter and only show records where DateRangeFlag equals "Yes."
If this still doesn’t resolve the issue, another approach could be to use calculated columns instead of measures, which might simplify the logic and ensure the correct context is applied.
Let me know if this helps or if you need further assistance!
Thank you!
A function 'PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
This error is populating when i try to create the measure mentioned above.
Hi @GokulBALAJI ,
Which of 3 measures give's your that error?
selectedstartdate
This measure is from another user, please double check my post and let me know if you are facing any issue, in my solution i dont have this measure.
Thank you
Please share a simplified version of your PBIX file (in English) without sensitive data. You can upload it to a public cloud service like OneDrive, Google Drive, or Dropbox and share the link. This will help in understanding your data structure and the issue, allowing for more precise guidance.
Hi @Kedar_Pande , i can't share it here. I dont see the option to upload the report in this portal.
Create Measures
SelectedStartDate =
CALCULATE(MAX('Table A'[Start Date]), 'Table A'[ID] = SELECTEDVALUE('Table A'[ID]))
SelectedDays = SELECTEDVALUE('Table B'[No of Days], 0)
StartOfRange = [SelectedStartDate] - [SelectedDays]
EndOfRange = [SelectedStartDate] + [SelectedDays]
DateRangeFlag =
IF('Table A'[Start Date] >= [StartOfRange] && 'Table A'[Start Date] <= [EndOfRange], "Yes", "No")
Use DateRangeFlag in the visual filter on Page 2 and set it to “Yes” to display records within the specified date range.
💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn
Hi @GokulBALAJI ,
It looks like you’re on the right track with your DAX formula, but there are a few adjustments needed to achieve the desired functionality. Here’s a step-by-step approach to help you:
Create two measures to capture the selected ID and No of Days from the slicers:
SelectedID = SELECTEDVALUE('Table A'[ID])
SelectedNumberofDays = SELECTEDVALUE('Table B'[No of Days])
Create a measure to capture the Start Date based on the selected ID:
SelectedStartDate =
CALCULATE(
MAX('Table A'[Start Date]),
FILTER('Table A', 'Table A'[ID] = [SelectedID])
)
Now, define startdate and enddate based on SelectedStartDate and SelectedNumberofDays
DateRangeFlag =
VAR selectedstartdate = [SelectedStartDate]
VAR days = [SelectedNumberofDays]
VAR startdate = selectedstartdate - days
VAR enddate = selectedstartdate + days
VAR selecteddate = MAX('Table A'[Start Date])
RETURN
IF(selecteddate >= startdate && selecteddate <= enddate, "Yes", "No")
Use the DateRangeFlag measure in a visual (like a table or card) to show which dates fall within the calculated range. This approach should dynamically adjust the date range based on your slicer selections.
I hope this help you, and if so, please consider to mark this reply as solution and give a Kudo.
Thank you!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
88 | |
86 | |
83 | |
64 | |
49 |
User | Count |
---|---|
127 | |
108 | |
88 | |
70 | |
66 |