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
zwaters3
Helper I
Helper I

is there a way to filter a table by a column added to it in a single expression

Hey guys, is there a way to perform this sort of operation?:

New Table = 
VAR crossjoinedAB = CROSSJOIN('tableA', 'tableB'
VAR crossjoinedABwithNewCol = AddColumn(crossjoinedAB, "FilterByThisColumn", IF( [ColumnInA] = 1, 1, 0))
RETURN CALCULATETABLE(crossjoinedABwithNewCol, [FilterByThisColumn] = 1)

As of right now I cannot get away with adding a new column, and then filtering by it in the same expression. I can get around this by splitting this into two parts, where part 1 makes the table with the new column

New Table = 
VAR crossjoinedAB = CROSSJOIN('tableA', 'tableB'
VAR crossjoinedABwithNewCol = AddColumn(crossjoinedAB, "FilterByThisColumn", IF( [ColumnInA] = 1, 1, 0))

and part 2, is when I make ANOTHER new table to filter it.

New Table2 = 
RETURN CALCULATETABLE('New Table', [FilterByThisColumn] = 1)

Is there a way to do this in a single step, without having to create an intermediary table?

1 ACCEPTED SOLUTION

Hi @zwaters3 ,

 

try this

New Table = 
VAR crossjoinedAB = CROSSJOIN('tableA', 'tableB')
VAR crossjoinedABwithNewCol = ADDCOLUMNS(crossjoinedAB, "FilterByThisColumn", IF( [ColumnInA] = 1, 1, 0))
RETURN FILTER(crossjoinedABwithNewCol, [FilterByThisColumn] = 1)
Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


View solution in original post

6 REPLIES 6

Hi @zwaters3 ,

 

why don't you use power query for transformation?

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


I already have this transformation up and running through power query, I'm just trying to recreate it for testing which loads faster. 

Hi @zwaters3 ,

 

try this

New Table = 
VAR crossjoinedAB = CROSSJOIN('tableA', 'tableB')
VAR crossjoinedABwithNewCol = ADDCOLUMNS(crossjoinedAB, "FilterByThisColumn", IF( [ColumnInA] = 1, 1, 0))
RETURN FILTER(crossjoinedABwithNewCol, [FilterByThisColumn] = 1)
Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


Hi @zwaters3 ,

 

from experience I would say Power Query.
Power Query has the advantage that with query folding, the data may already be filtered in the source and that the result is saved with a higher compression.

 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Marcus Wegener works as Full Stack Power BI Engineer at BI or DIE.
His mission is clear: "Get the most out of data, with Power BI."
twitter - LinkedIn - YouTube - website - podcast


I understand that may be true, but I would still prefer to have an answer to my original question. 

sorry, you provided the answer just as I responded to your previous post

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.