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
UsePowerBI
Post Prodigy
Post Prodigy

CALCULATETABLE syntax?

Hello

 

Can CALCULATETABLE create a table from another table using:

1) columns matching (in) a specific list/array of column names

2) rows for each separately or all of the above filtered columns, matching specific criteria

 

So for example from the source table below:

Col1Col2Col3
A01/01/20001
B02/01/20002
C03/01/20003

 

To be able to CALCULATETABLE the below:

Col1Col3
A2
B4

 

By choosing all columns that are in the list {Col1,Col3} and all rows that match Col2=CALCULATE(MAX(Col2),ALLEXCEPT(Col1)) (i.e. the rows where Col2 is the maximum date for each value of Col1.

 

I think the CALCULATETABLE, ADDCOLUMNS, SELECTCOLUMNS accept literal Column Names and not expressions and also you need to specify each one by one and not in a list?

 

Thanks! 

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @UsePowerBI ,

 

I think you may try this code to create a new table.

Table 2 = 
SELECTCOLUMNS (
    FILTER (
        'Table',
        VAR _MAX_COL2 =
            CALCULATE ( MAX ( 'Table'[Col2] ), ALLEXCEPT ( 'Table', 'Table'[Col1] ) )
        RETURN
            'Table'[Col2] = _MAX_COL2
    ),
    "Col1", 'Table'[Col1],
    "Col3", 'Table'[Col3]
)

My Sample:

RicoZhou_0-1658913449412.png

Result is as below.

RicoZhou_1-1658913477009.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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @UsePowerBI ,

 

I think you may try this code to create a new table.

Table 2 = 
SELECTCOLUMNS (
    FILTER (
        'Table',
        VAR _MAX_COL2 =
            CALCULATE ( MAX ( 'Table'[Col2] ), ALLEXCEPT ( 'Table', 'Table'[Col1] ) )
        RETURN
            'Table'[Col2] = _MAX_COL2
    ),
    "Col1", 'Table'[Col1],
    "Col3", 'Table'[Col3]
)

My Sample:

RicoZhou_0-1658913449412.png

Result is as below.

RicoZhou_1-1658913477009.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.

littlemojopuppy
Community Champion
Community Champion

Hi @UsePowerBI 

 

Take a look at the GENERATE function.  It allows you to create joins where there may not be lineage.

This isn't going to be syntactically accurate because I'm typing it in Notepad.  But it should get you close...

GENERATE(
	TableA,
	FILTER(
		TableB,
		Col1 = EARLIER(TableA[Col1)
	)
)

Hope this helps!

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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