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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
MatiasAraya
New Member

DAX equivalent for nested SQL query

Hello:

I'm trying to express this query into DAX, because using SQL queries is not posible in the current env I'm working on.

 

 

select ID, MAX(YEAR), NAME, SPECIALIZATION
    from STUDENTS_TABLE A
    where not exists 
    ( select distinct B.YEAR, B.ID
        from STUDENTS_TABLE B
        where B.YEAR in (A.YEAR - 1,A.YEAR - 2) and A.ID=B.ID
    )
    order by A.ID ,A.YEAR
    group by (A.ID);
 
Any help would be appreciated

 

1 REPLY 1
ThxAlot
Super User
Super User

Which sql dialect do you use? It seems the syntax is wrong ...

select ID
	, MAX(YEAR) as max_yr
	, NAME
	, SPECIALIZATION
from STUDENTS_TABLE A
where not exists 
	( select NULL
		from STUDENTS_TABLE B
		where B.YEAR in (A.YEAR - 1,A.YEAR - 2) and A.ID=B.ID
	)
group by A.ID, A.NAME, A.SPECIALIZATION
Table =
SUMMARIZECOLUMNS(
    STUDENTS_TABLE[ID], STUDENTS_TABLE[NAME], STUDENTS_TABLE[SPECIALIZATION],
    "max_yr",
    MAXX(
        FILTER(
            VALUES( STUDENTS_TABLE[Year] ),
            VAR __yr = STUDENTS_TABLE[Year]
            RETURN
                ISEMPTY(
                    FILTER(
                        VALUES( STUDENTS_TABLE[Year] ),
                        STUDENTS_TABLE[Year] IN { __yr - 1, __yr - 2 }
                    )
                )
        ),
        STUDENTS_TABLE[Year]
    )
)


Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.