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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Unable to filter by a VAR value

I’ve created a date table that has an índex colum sorted by date.

 

Ran the following tests:

EVALUATE
VAR nDayIndex =
    SELECTCOLUMNS ( FILTER ( Dates, Dates[Date] = TODAY () ), "Id", Dates[Index] )
RETURN
    nDayIndex

pic 1.PNG

 

I was expecting the following code to work but it doesn't:

EVALUATE
VAR nDayIndex =
    SELECTCOLUMNS ( FILTER ( Dates, Dates[Date] = TODAY () ), "Id", Dates[Index] )
RETURN
    FILTER ( Dates, Dates[Index] = nDayIndex )

The error I'm getting is:

pic2.PNG

 

What intrigues me is that the following works:

EVALUATE
var nDay=601
return
FILTER(Dates,Dates[Index]=nDay)

pic3.PNG

 

Can anyone explain why it doesn't work? 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Okay, maybe I did things a little to fast 🙂 Sorry...

 

But since the variable returns a table (with lineage to the original table) it should be possible to use it as a filter condition in for example a Calculatetable

 

I tested this with your file and in returned the relevant row in the Dates table

 

EVALUATE
var nDayIndex = SELECTCOLUMNS(FILTER(Dates,Dates[Date] = TODAY()),"Id",Dates[Index])
return
CALCULATETABLE(Dates,nDayIndex)  

 

Skärmklipp.PNG

 

Br,

Magnus

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi,

 

Your variable nDayIndex that is constructed from SELECTCOLUMNS will return a table with only one column an one row. To use that as a scalar value in a FILTER expression you need to refer to the actual value in the resulting table. The following example will give you the desired result.

 

EVALUATE
VAR nDayIndex =
    SELECTCOLUMNS ( FILTER ( Dates, Dates[Date] = TODAY () ), "Id", Dates[Index] )
RETURN
    FILTER ( Dates, Dates[Index] = Values(nDayIndex[Id] )

 

Br,

Magnus

Anonymous
Not applicable

Doens't workDoens't work

Here is a link to the pbix if someone wants to look at it:
https://www.dropbox.com/s/39hlb33wfjbu6a7/VarProblem.pbix?dl=0

Hi @Anonymous,

 

Current variable table not support to use 'variable Name'[Column Name], it only works on static tables.

 

For your scenario, you can try to use below formula to filter date by today function.

New Table =
VAR nDayIndex =
    CALCULATETABLE (
        VALUES ( Dates[Index] ),
        FILTER ( ALL ( Dates ), [Date] = TODAY () )
    )
RETURN
    FILTER ( Dates, CONTAINS ( nDayIndex, Dates[Index], [Index] ) )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Okay, maybe I did things a little to fast 🙂 Sorry...

 

But since the variable returns a table (with lineage to the original table) it should be possible to use it as a filter condition in for example a Calculatetable

 

I tested this with your file and in returned the relevant row in the Dates table

 

EVALUATE
var nDayIndex = SELECTCOLUMNS(FILTER(Dates,Dates[Date] = TODAY()),"Id",Dates[Index])
return
CALCULATETABLE(Dates,nDayIndex)  

 

Skärmklipp.PNG

 

Br,

Magnus

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.