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
yussuf020
New Member

DAX query to change column information based on selected date range

Hey,

I need some help with putting together a dax query. 

 

1. What I need is Status column that returns either (Active/Inative), if the Comment Date field is between the start and end date of the selected Date filter. In the image below, I am currently receiving an 'Active' status, however, the intended status I expect to see 'Inactive' status. 

2. The table should not filter out any suburbs that are not within the selected Date range. 

yussuf020_2-1673171507605.png

 

Here is my current relationship:

yussuf020_1-1673170166666.png

 

Here is the current status dax query I am using

Status = 

VAR firstselecteddate = FIRSTDATE('Calendar'[Date])
VAR lastselecteddate = LASTDATE('Calendar'[Date])

RETURN

If(
    Table1[Comment Date] >= firstselecteddate || Table1[Comment Date] <= lastselecteddate , "Active", "Inactive"
)
 
Any help would be appreciated. Thanks in advance
1 ACCEPTED SOLUTION
yussuf020
New Member

Update: I have found what I needed to do via the following link: 

https://radacad.com/power-bi-from-and-to-date-filtering-with-one-slicer

 

Thank you for your responses. 

View solution in original post

6 REPLIES 6
yussuf020
New Member

Update: I have found what I needed to do via the following link: 

https://radacad.com/power-bi-from-and-to-date-filtering-with-one-slicer

 

Thank you for your responses. 

Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hey @Ashish_Mathur ,

 

Here is a copy of the PBI file: https://1drv.ms/u/s!AsNILaiR3etzhR5-qjmALmnh_nkg?e=J3NSzJ

 

Thanks for responding

I'm using a disconnected date table with the following measure:

Status = 
VAR firstselecteddate = MIN( 'Calendar'[Date] )
VAR lastselecteddate = MAX( 'Calendar'[Date] )
VAR result = 
    IF(
        SELECTEDVALUE( Table1[Comment Date] ) >= firstselecteddate
            && SELECTEDVALUE( Table1[Comment Date] ) <= lastselecteddate,
        "Active",
        "Inactive"
    )
RETURN
    result

https://1drv.ms/u/s!AnF6rI36HAVkhPIamxvEeIJyEPNBXw?e=fuawQP

 

adudani
Super User
Super User

HI @yussuf020 ,

try 

Status = 

VAR firstselecteddate = FIRSTDATE('Calendar'[Date])
VAR lastselecteddate = LASTDATE('Calendar'[Date])

RETURN

If(
    Table1[Comment Date] >= firstselecteddate && Table1[Comment Date] <= lastselecteddate , "Active", "Inactive"
)

 

the && will give datesbetween selected values of first selected date and last selected date.
However, please note. the first date value = the Start/minimum date in the date table. it is not the selected value from the slicer.



if this doesn't work, kindly provide the action date as well in a copy-paste table format.

Appreciate a thumbs up if this helps.

 

Please accept this as the solution if your query is resolved.

Did I answer your question? Mark my post as a solution, this will help others!
If my response(s) assisted you in any way, don't forget to drop me a Kudos 🙂
Kind Regards,
Avinash

Hey @adudani ,

 

I have tried using && instead of || however this has not made a difference. 

 

Here is a link to the file if that will help?

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.