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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
drew_darke
Frequent Visitor

Using DAX to get the most recent date up to today's ("NOW()") date

drew_darke_0-1629142269914.png

I have this range of dates that are at the row level. Each date represents another field that was updated. It also has future dates as the fields have scheduled updates.

I would like to get the following measures:
Starting Value: This is easy because we can just use FIRSTDATE to grab that.
Current Value: This is where I am struggling. Using LASTDATE does not work because it will grab the highest date in the column (2023) but we want the LASTDATE from NOW() using the Now function as a ceiling for the lastdate function. The ideal value it would return is the 2021 row, because January 2021 is the most recent date.

Note: Using any YEAR calculations may not work with the rest of the data as some things change once a year like with this example, but also it could change every couple months.

 

3 ACCEPTED SOLUTIONS

@drew_darke Right, you have to use proper syntax for SELECTEDCOLUMNS, I just used ... because I didn't know your columns and am lazy. So, something like:

Current Value = CALCULATE(MAX(Table[Value]), LASTDATE((SELECTCOLUMNS(FILTER(Table, Table[Date] <= NOW()),"Date",[Date])))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

parry2k
Super User
Super User

@drew_darke or something like this

 

Last date measure = 
CALCULATE ( MAX ( Table[Date] ), ALLSELECTED ( Table ), Table[Date] <= NOW() ) )

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

v-rzhou-msft
Community Support
Community Support

Hi @drew_darke 

Try this measure.

Measure = CALCULATE(MAX('Table'[Value]), LASTDATE(CALCULATETABLE(VALUES('Table'[Date]),FILTER('Table','Table'[Date]<NOW()))))

If this measure still couldn't help you solve your problem, please share a sample with me without sensitive data by your Onedrive for Business.

 

Best Regards,
Rico Zhou

 

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

9 REPLIES 9
v-rzhou-msft
Community Support
Community Support

Hi @drew_darke 

Try this measure.

Measure = CALCULATE(MAX('Table'[Value]), LASTDATE(CALCULATETABLE(VALUES('Table'[Date]),FILTER('Table','Table'[Date]<NOW()))))

If this measure still couldn't help you solve your problem, please share a sample with me without sensitive data by your Onedrive for Business.

 

Best Regards,
Rico Zhou

 

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

parry2k
Super User
Super User

@drew_darke or something like this

 

Last date measure = 
CALCULATE ( MAX ( Table[Date] ), ALLSELECTED ( Table ), Table[Date] <= NOW() ) )

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Greg_Deckler
Super User
Super User

@drew_darke Can you not just use LASTDATE(SELECTCOLUMNS(FILTER('Table',[Date]<NOW())...))


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Current Value = CALCULATE(MAX(Table[Value]), LASTDATE((SELECTCOLUMNS(FILTER(Table, Table[Date] <= NOW())))))

I am receiving an error saying SELECTCOLUMNS function needs 2 arguments.

Also I want to clear up that I am not after the date itself, but the value in another column the date is keyed for.

@drew_darke Right, you have to use proper syntax for SELECTEDCOLUMNS, I just used ... because I didn't know your columns and am lazy. So, something like:

Current Value = CALCULATE(MAX(Table[Value]), LASTDATE((SELECTCOLUMNS(FILTER(Table, Table[Date] <= NOW()),"Date",[Date])))

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Hello - Please forgive me if I'm not using correct forum etiquette by replying to a closed thread, but this is the closest answer I've found. 
I'm getting error "Function 'LASTDATE' cannot be used with columns added by ADDCOLUMNS or SUMMARIZE functions".  This is the measure I'm using

 

Current Balance = 
    CALCULATE(
        SUM('Deposits'[CurrentBalance])
        ,LASTDATE(
            SELECTCOLUMNS(
                FILTER('Date','Date'[Calendar Date]<NOW())
                ,"Date",'Date'[Calendar Date]
            )
        )
    )

 

My date table has future dates in it and it sounded like this was the closest solution, but I can't figure out what I'm doing wrong.  Any assistance would be greatly appreciated!

Try:

Current Balance = 
  VAR __LastDate = 
    MAXX(
      FILTER('Date', [Calendar Date]<NOW()),
      [Calendar Date]
    )
  VAR __Result = SUMX(FILTER('Deposits', [Date] = __LastDate), [CurrentBalance])
RETURN
  __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler
I am trying to do the same on my PBI. 
here are my column names and I need to find the last status update. I created a new column that combines the last event day and time. 

Customer Confirmation NumberDelivery Confirmation NumberManifest DateReceive DateLast Event DateLast Event TimeLast Event DescriptionZip or Postal Code

 

Please let me know how I should go about getting this most recent status. 

I tried to use the following but its not pulling back the latest status:

Last Status =
VAR CustomerNumber = 'DHL Status'[Delivery Confirmation Number]

RETURN
maxx(FILTER(ALL('DHL Status'), 'DHL Status'[Delivery Confirmation Number] = CustomerNumber),
    'DHL Status'[Last Event Description])

That worked!! Thanks so much 🙂

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.