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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Kolumam
Post Prodigy
Post Prodigy

DAX formula to retreive a value of a column based on a date field in another column

How do I retreive a value of a column based on the most recent date of another column ?

1 ACCEPTED SOLUTION

Hi @Kolumam

 

replace [Last_Date] in the last line with just secondLast_Date

 

secondLast_Date should be without brackets because it is the variable in the same formula

 

 

 

 

 

 

View solution in original post

13 REPLIES 13
Zubair_Muhammad
Community Champion
Community Champion

Hi @Kolumam

 

Do you mean Column or Table?

 

Please could you paste 5-6 rows of sample data and expected result?

WhatsApp Image 2017-11-27 at 6.22.37 PM.jpeg

So there are two columns here. The measure should display the value of "Percentage Solar over Load" based on the most recen date (i.e. 27/11/2017)

HI @Kolumam

 

Please try these MEASURES.

I am assuming Percentage Solar Over Load is a MEASURE

 

 

LastDate =
LASTDATE ( ALL ( Table1[Date] ) )

 

%age on LastDate=
VAR Last_Date =
    LASTDATE ( ALL ( Table1[Date] ) )
RETURN
    CALCULATE ( [Percentage Solar over Load], Table1[Date] = Last_Date )

Hi Zubair,

 

Percentage Solar over load is just a column from excel sheet.

Hi Zubair

 

Instead of retreiving the value based on the most recet date, is it possible to retreive based on yesterday date ? (26/11/2017)

Hi @Kolumam

 

Just Wrap LastDate with PreviousDay

 

 

Last_Date = PREVIOUSDAY(LastDate(All(Table1[Date])))

 

@Kolumam

 

SecondLastDate =
PreviousDay(LASTDATE ( ALL ( Table1[Date] ) ))

 

%age on SecondLastDate=
VAR SecondLast_Date =
    PreviousDay(LASTDATE ( ALL ( Table1[Date] ) ))
RETURN
    CALCULATE ( [Percentage Solar over Load], Table1[Date] = SecondLast_Date )

MR.PNG

 

Not sure why it is able to find the column ?

@Kolumam

 

So its a Column. I thought its a MEASURE

 

Use Calculate(sum(Meter REadings[Percentage Solar Overload])

 

calculate cannot have simple columns as arguments

MD.PNG

 

It gives me this error now.

Hi @Kolumam

 

replace [Last_Date] in the last line with just secondLast_Date

 

secondLast_Date should be without brackets because it is the variable in the same formula

 

 

 

 

 

 

I realized the mistake yesterday itself. Thanks for your immense help.

Hi Zubair,

 

The formula that you suggested a few months back is not working now. all of a sudden it has gone blank. It says data format is not supported.

 

Could you please help me with my query ?

http://community.powerbi.com/t5/Desktop/Error-with-DAX-formula/m-p/338849#M151633

 

Thanks

Krishna

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors