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

Get 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

Reply
user35131
Helper III
Helper III

How do i filter using a max variable within a variable chain while creating a table

i have a formula that looks like this. This works and gives me date above 01,01,2022

 

 

 

Final Table = 

Var Table1=

"Pulled a table out of here

Var Table2 =

ADDCOLUMNS(Table1,"rank_order", RANKX(FILTER(Table1,[id]=EARLIER([id])),[date],,ASC,Dense))

var Table3 = 
FILTER(Table2,[date] >= DATE(2022,01,01))

return Table3

 

 

 

However I want to do something like this becasue I want to create a dynamic table outcome.

 

 

Var Table1=

"Pulled a table out of here

Var Table2 =

ADDCOLUMNS(Table1,"rank_order", RANKX(FILTER(Table1,[id]=EARLIER([id])),[date],,ASC,Dense))

var Table3 = 
FILTER(Table2,[date] >= DATE(MAX(Table2[date]),01,01))

return Table3

 

 

 

note before I had Date(2022,01,01), but I want Date(Max(table2[date]),01,01). However when I try to do it this way I get "Cannot identify the table that contains [date] column.

 

 

1 ACCEPTED SOLUTION

Hi @user35131 ,

 

I checked your code and I think Table2 should be a virtual table in your calculated table code. We couldn't use MAX to determind the column [Date] in virtual table directly. So you will get this error. You can try MAXX function to do this.

 

Table =
VAR _Table1 = 
"Pulled a table out of here"
VAR _Table2 =
    ADDCOLUMNS (
        _Table1,
        "rank_order", RANKX ( FILTER ( _Table1, [id] = EARLIER ( [id] ) ), [date],, ASC, DENSE )
    )
VAR _Table3 =
    FILTER ( _Table2, [date] >= DATE ( YEAR ( MAXX ( _Table2, [Date] ) ), 01, 01 ) )
RETURN
    _Table3

My Sample:

 

1.png

Result is as below.

2.png

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
amitchandak
Super User
Super User

@user35131 , try table 3 like 

 

var Table3 =
FILTER(Table2,[date] >= DATE(year(MAX(Table2[date])),01,01))

return Table3

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

I got the same response that said cannot identify the table that contains [date] column.

Hi @user35131 ,

 

I checked your code and I think Table2 should be a virtual table in your calculated table code. We couldn't use MAX to determind the column [Date] in virtual table directly. So you will get this error. You can try MAXX function to do this.

 

Table =
VAR _Table1 = 
"Pulled a table out of here"
VAR _Table2 =
    ADDCOLUMNS (
        _Table1,
        "rank_order", RANKX ( FILTER ( _Table1, [id] = EARLIER ( [id] ) ), [date],, ASC, DENSE )
    )
VAR _Table3 =
    FILTER ( _Table2, [date] >= DATE ( YEAR ( MAXX ( _Table2, [Date] ) ), 01, 01 ) )
RETURN
    _Table3

My Sample:

 

1.png

Result is as below.

2.png

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.