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

DAX column measure 1 for max date else 0

Hi 

 

I have a table with lots of property references that apear multiple times but with different dates. I would like to create a calculated column that returns 1 for the max date relating to each of these references els return 0

 

RefDateDAX - Max Date
13233216/06/20110
13233218/01/20140
13233210/11/20150
13233224/04/20170
13233203/04/20200
13233211/05/20201
9000016/06/20110
9000018/01/20140
9000010/11/20150
9000024/04/20170
9000003/04/20200
9000011/05/20211

 

thank you

RIchard

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @cottrera ,

 

try the following calculated column. I added some explanation in the code:

 

 

MaxDate =
-- Calculate the MAX date for the current REF-ID
VAR vMaxDate = CALCULATE ( MAX ( myTable[Date] ), ALLEXCEPT ( myTable, myTable[Ref] ) )
RETURN
    -- When the date of the current row is equal to the vMaxDate then return 1 otherwise 0
    IF (
        myTable[Date] = vMaxDate,
        1,
        0
    )

 

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

3 REPLIES 3
cottrera
Post Prodigy
Post Prodigy

Appologies Denis my data model was Direct Query. When I changed it to Import your measure worked fine 😁

cottrera
Post Prodigy
Post Prodigy

Hi Denis thank you for your quick reponse. I am getting these errors when adding the code to a column measure

cottrera_0-1632132972253.png

Richard

selimovd
Super User
Super User

Hey @cottrera ,

 

try the following calculated column. I added some explanation in the code:

 

 

MaxDate =
-- Calculate the MAX date for the current REF-ID
VAR vMaxDate = CALCULATE ( MAX ( myTable[Date] ), ALLEXCEPT ( myTable, myTable[Ref] ) )
RETURN
    -- When the date of the current row is equal to the vMaxDate then return 1 otherwise 0
    IF (
        myTable[Date] = vMaxDate,
        1,
        0
    )

 

 

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

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.