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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
kirti_agarwal28
Frequent Visitor

dax formula for selecting sum of Id where date is latest

Hi All,

 

I am new user of Power BI and  need a help in writing DAX Query for one measure:

 

input data:

ID values Date
1 2 1-Oct
1 2 1-sept
1 3 1-Aug
2 5 1-Aug
2 6 1-sept
2 7 1-July
3 2 1-July
3 1 1-June


Result:
ID values Date
1      2     1-Oct
2      6     1-sept
3      2     1-July

 

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@kirti_agarwal28 

 

Create the following measure and assign it to the table visual filter and set it equal to 1.

 

 

Flag = 
VAR _DATE = 
    CALCULATE(
        MAX(Table11[DATE]),
        ALLEXCEPT(Table11,Table11[ID])
    )
VAR _VALUE = 
    CALCULATE(
        MAX(Table11[VALUE]),
        Table11[DATE] = _DATE,
        ALLEXCEPT(Table11,Table11[ID])
    )
RETURN
IF( SELECTEDVALUE(Table11[DATE]) = _DATE && SELECTEDVALUE(Table11[VALUE]) = _VALUE,
    1,
    0
)

 

Screenshot 2020-11-05 182136.png

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

4 REPLIES 4
kirti_agarwal28
Frequent Visitor

Thanks @Fowmy 

Anonymous
Not applicable

 

// This measure will show you the latest
// value if only one ID is visible in
// the current context. For this to work
// there can't be duplicated dates within
// one and the same ID, which is the case
// in your test data. If this is not true,
// then you won't be able to pick a unique
// value.
[Latest Value] =
IF( HASONEFILTER( T[ID] ),
    MAXX(
        topn(1,
            T,
            T[Date], // must be of the date(time) type
            DESC
        ),
        T[Value]
    )
)

// The second accompanying measure.
[Latest Date] =
IF( HASONEFILTER( T[ID] ),
    MAXX(
        topn(1,
            T,
            T[Date], // must be of the date(time) type
            DESC
        ),
        T[Date]
    )
)

To see this working just drop ID's on the canvas and then the measures.

 

amitchandak
Super User
Super User

@kirti_agarwal28 , Create these two measures and use with ID

max Date = max(Table[Date])
latest value = lastnonblankvalue(Table[Date],max(Table[values]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Fowmy
Super User
Super User

@kirti_agarwal28 

 

Create the following measure and assign it to the table visual filter and set it equal to 1.

 

 

Flag = 
VAR _DATE = 
    CALCULATE(
        MAX(Table11[DATE]),
        ALLEXCEPT(Table11,Table11[ID])
    )
VAR _VALUE = 
    CALCULATE(
        MAX(Table11[VALUE]),
        Table11[DATE] = _DATE,
        ALLEXCEPT(Table11,Table11[ID])
    )
RETURN
IF( SELECTEDVALUE(Table11[DATE]) = _DATE && SELECTEDVALUE(Table11[VALUE]) = _VALUE,
    1,
    0
)

 

Screenshot 2020-11-05 182136.png

 

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.