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

Measure - SQL to DAX, How to use

Hi

I have an SQL query that I want to convert to DAX and I don't know how to do it. can you help me? 

in the table, I have an ID field, date field, and other fields. I want to return for every ID the line in which the date is the latest (= the most current status of the ID).

 

select *
from table as t
where t.date >= All (select date from table as t1 where t.id=t1.id)

 

this is the DAX query I tried to use when I had only one ID (it works). but once I have more than one ID it needs to be altered.

show_last_date =
VAR LatestDate =
CALCULATE ( MAX ( 'table'[date] ), ALL ( 'table' ) )
RETURN
IF ( MIN ( 'table'[date] ) = LatestDate, 1, 0 )

 

also, after I have a working measure, is there a way to not show it as a field in the table? (I'm using a multi-row card which I can't minimize columns in)

thanks!

1 ACCEPTED SOLUTION

hi, @ifat_c 

You should use ALLEXCEPT Function as below:

show_last_date = 
VAR LatestDate =
CALCULATE ( MAX ( 'table'[date] ), ALLEXCEPT('Table','Table'[ID ]))
RETURN
IF ( MIN ( 'table'[date] ) = LatestDate, 1, 0 )

And just drag the measrue into Visual level filter of the visual not into Value and set is "1"

2.JPG

 

here is pbix file, please try it.

 

Best Regards,

Lin

 

Community Support Team _ Lin
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

5 REPLIES 5
v-lili6-msft
Community Support
Community Support

hi, @ifat_c 

from your measure “this is the DAX query I tried to use when I had only one ID (it works)” and your description, I think the logic is a mess, So could you share you some simple sample data and expected output.

Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Best Regards,

Lin

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

Hi, I'll try to be more specific.

in the table, I have an ID field, date field, and other fields. I want to return for every ID the line in which the date is the latest (= the most current status of the ID).

 

this is the SQL query I would use to do this:

select *
from table as t
where t.date >= All (select date from table as t1 where t.id=t1.id)

 

I need your help to translate it to DAX to use as a measure

sample data:

ID Datenamestatus
101/01/2019aon
201/01/2019boff
301/02/2019con
201/02/2019bon
301/01/2019con
101/02/2019aoff

 

desired outcome:

ID Datenamestatus
301/02/2019con
201/02/2019bon
101/02/2019aoff

hi, @ifat_c 

You should use ALLEXCEPT Function as below:

show_last_date = 
VAR LatestDate =
CALCULATE ( MAX ( 'table'[date] ), ALLEXCEPT('Table','Table'[ID ]))
RETURN
IF ( MIN ( 'table'[date] ) = LatestDate, 1, 0 )

And just drag the measrue into Visual level filter of the visual not into Value and set is "1"

2.JPG

 

here is pbix file, please try it.

 

Best Regards,

Lin

 

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

thank you so much!! it works now!

and how do you not present the show_last_date column?

never mind, got it!

just needed to remove it from "fields"

thank you!

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.