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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
hiolgh
Frequent Visitor

FILTERing a value from a RELATEDTABLE

Hi all

 

I have two tables, 'LGZ Schools' (1) <---> (*) 'CountYourCarbon'.

They're joined as follows: 'LGZ Schools'[_School ID] <---> 'CountYourCarbon'[sfct_letsgozero]

 

'CountYourCarbon' has three fields: [sfct_letsgozero], [CYC Date] and [CYC Score (Tonnes)].

 

I'm trying to read a value from CountYourCarbon into a new column called "Baseline" in LGZ Schools. I want to filter CountYourCarbon for where there's a match on [_School ID]<--->[sfct_letsgozero], which will return between 0 and 2 rows, then filter that for the earliest date in the [CYC Date] field, and then return the value in the field [CYC Score (Tonnes)].

 

The best I've got so far is:

 
Baseline =
    SELECTCOLUMNS(
        FILTER(
            FILTER(
                RELATEDTABLE(CountYourCarbon),
                'CountYourCarbon'[sfct_letsgozero]='LGZ Schools'[_School ID]
                ),
            [CYC Date]=MIN([CYC Date])
        )
        "Baseline",
        [CYC Score (Tonnes)]
    )
 
I'm getting the error "The syntax for '"Baseline"' is incorrect."
 
Can you please advise?
 
Thanks.
2 ACCEPTED SOLUTIONS
techies
Super User
Super User

Hi @hiolgh please try this calculated column

 

Baseline =
VAR RelatedRows =
    FILTER (
        CountYourCarbon,
        CountYourCarbon[sfct_letsgozero] = 'LGZ Schools'[_School ID]
    )
VAR EarliestDate =
    CALCULATE (
        MIN (CountYourCarbon[CYC Date]),
        RelatedRows
    )
RETURN
    CALCULATE (
        MAX (CountYourCarbon[CYC Score (Tonnes)]),
        FILTER (
            RelatedRows,
            CountYourCarbon[CYC Date] = EarliestDate
        )
    )
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

View solution in original post

Anonymous
Not applicable

Hi @hiolgh ,
Thank you @techies for the prompt response!

Upon reviewing the information provided,I tried to create it locally.
 Try using the below calculated column:

Baseline =
VAR SchoolID = 'LGZ Schools'[_School ID]
VAR FilteredTable =
    FILTER (
        'CountYourCarbon',
        'CountYourCarbon'[sfct_letsgozero] = SchoolID
    )
VAR MinDate =
    CALCULATE (
        MIN ( 'CountYourCarbon'[CYC Date] ),
        FilteredTable
    )
VAR Result =
    CALCULATE (
        MAX ( 'CountYourCarbon'[CYC Score (Tonnes)] ),
        FILTER (
            FilteredTable,
            'CountYourCarbon'[CYC Date] = MinDate
        )
    )
RETURN
    Result

Please refer the screenshot and the file for your reference.
vpagayammsft_0-1746592283582.png


If the solution meets your requirement,consider accepting it as solution.

Thank you for being a part of Microsoft Fabic Community Forum!

Regards,
Pallavi.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @hiolgh ,
Thank you @techies for the prompt response!

Upon reviewing the information provided,I tried to create it locally.
 Try using the below calculated column:

Baseline =
VAR SchoolID = 'LGZ Schools'[_School ID]
VAR FilteredTable =
    FILTER (
        'CountYourCarbon',
        'CountYourCarbon'[sfct_letsgozero] = SchoolID
    )
VAR MinDate =
    CALCULATE (
        MIN ( 'CountYourCarbon'[CYC Date] ),
        FilteredTable
    )
VAR Result =
    CALCULATE (
        MAX ( 'CountYourCarbon'[CYC Score (Tonnes)] ),
        FILTER (
            FilteredTable,
            'CountYourCarbon'[CYC Date] = MinDate
        )
    )
RETURN
    Result

Please refer the screenshot and the file for your reference.
vpagayammsft_0-1746592283582.png


If the solution meets your requirement,consider accepting it as solution.

Thank you for being a part of Microsoft Fabic Community Forum!

Regards,
Pallavi.

Thanks for taking the time to recreate the tables! 

techies
Super User
Super User

Hi @hiolgh please try this calculated column

 

Baseline =
VAR RelatedRows =
    FILTER (
        CountYourCarbon,
        CountYourCarbon[sfct_letsgozero] = 'LGZ Schools'[_School ID]
    )
VAR EarliestDate =
    CALCULATE (
        MIN (CountYourCarbon[CYC Date]),
        RelatedRows
    )
RETURN
    CALCULATE (
        MAX (CountYourCarbon[CYC Score (Tonnes)]),
        FILTER (
            RelatedRows,
            CountYourCarbon[CYC Date] = EarliestDate
        )
    )
― Power BI | Microsoft Fabric | PL-300 | DP-600 | Blog: medium.com/@cseprs_54978

This is great thanks, and I'll learn from your approach. I had tried using variables but then I couldn't manipulate RelatedRows with further filters. I now see that using it to filter the original table is the way to go.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.