Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Spyrosmak
Frequent Visitor

Pass a parameter to dax query

Hello all,

 

I have filter in my table with a dax query:

 

IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= DATE(YEAR(TODAY()), 1, 1) &&
     'Main Query'[date] <= TODAY() ||
    'Main Query'[column1] = "Pending",
    1,
    0
)

This filter does the trick however, I would to be able to interact with DATE(YEAR(TODAY()), 1, 1)  and Today() from the frontend (with slicer or something). I have tried creating a date table and measures with startdate= min(date_table(date)) and stopdate = max(date_table(date)) but it didn't work and I cannot put a relationship from my new table to the old one because of duplicate dates issue. Does anyone know how instead of Today() I can have a variable that I can change dynamically with a visual(e.g. slicer ) for example?

Thank you
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Spyrosmak 

You can try the follwing solution.

the following is my test result.

Sample main table.

vxinruzhumsft_2-1727762372295.png

 

Calendar table.

vxinruzhumsft_3-1727762603287.png

Create the following measure 

IsInDateRangeOrPending(weekly) =
IF (
    SELECTEDVALUE ( 'Main Query'[date] ) >= FIRSTDATE ( Date_Table_end[Date] )
        && OR (
            SELECTEDVALUE ( 'Main Query'[date] ) <= LASTDATE ( Date_Table_end[Date] ),
            SELECTEDVALUE ( 'Main Query'[column1] ) = "Pending"
        ),
    1,
    0
)

Then put the measure to the visual filter.

vxinruzhumsft_4-1727762683138.png

 

Then put the date of clendar table to  a slicer, then it can work.

Output

vxinruzhumsft_5-1727762730202.pngvxinruzhumsft_6-1727762740078.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

6 REPLIES 6
Spyrosmak
Frequent Visitor

Hello,

I have tried this

IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= LASTDATE(Date_Table_end[Date])
 &&
     'Main Query'[date] <= FIRSTDATE(Date_Table_end[Date])
 ||
    'Main Query'[column1] = "Pending",
    1,
    0
)
but it produces different numbers on my table

than this
IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= DATE(YEAR(TODAY()), 1, 1) &&
     'Main Query'[date] <= TODAY() ||
    'Main Query'[column1] = "Pending",
    1,
    0
)


IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= LASTDATE(Date_Table_end[Date])
 &&
     'Main Query'[date] <= FIRSTDATE(Date_Table_end[Date])
 ||
    'Main Query'[column1] = "Pending",
    1,
    0
)
I don't know your data but intuatively should FIRST be >= and LAST <= they feel the wrong way around.

If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Hello yes you are right, I changed the order however now the filter doesn't work at all. It changes the dates effectively but it doesn't affect my table. (the date table doesn't have relationship with the main table)

Anonymous
Not applicable

Hi @Spyrosmak 

You can try the follwing solution.

the following is my test result.

Sample main table.

vxinruzhumsft_2-1727762372295.png

 

Calendar table.

vxinruzhumsft_3-1727762603287.png

Create the following measure 

IsInDateRangeOrPending(weekly) =
IF (
    SELECTEDVALUE ( 'Main Query'[date] ) >= FIRSTDATE ( Date_Table_end[Date] )
        && OR (
            SELECTEDVALUE ( 'Main Query'[date] ) <= LASTDATE ( Date_Table_end[Date] ),
            SELECTEDVALUE ( 'Main Query'[column1] ) = "Pending"
        ),
    1,
    0
)

Then put the measure to the visual filter.

vxinruzhumsft_4-1727762683138.png

 

Then put the date of clendar table to  a slicer, then it can work.

Output

vxinruzhumsft_5-1727762730202.pngvxinruzhumsft_6-1727762740078.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

SamWiseOwl
Super User
Super User

Hi @Spyrosmak 

This issue can be caused due to MIN not treating the returned value as a date.

Try using FirstDate() and LastDate() instead.

 

Is this trying to make a calculated column or a measure used in a table visual?


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Hello,

I have tried this

IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= LASTDATE(Date_Table_end[Date])
 &&
     'Main Query'[date] <= FIRSTDATE(Date_Table_end[Date])
 ||
    'Main Query'[column1] = "Pending",
    1,
    0
)
but it produces different numbers on my table

than this
IsInDateRangeOrPending(weekly) =
IF(
    ('Main Query'[date] >= DATE(YEAR(TODAY()), 1, 1) &&
     'Main Query'[date] <= TODAY() ||
    'Main Query'[column1] = "Pending",
    1,
    0
)

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors