cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
New Member

VAR works with a constant date but not in a formula

I'm already tired searching

 

This works in dax:

MySales =
   VAR ReportingMonth = month(DATEVALUE("05/01/2020"))
   RETURN CALCULATE(SUM(fDespesas[Dispêndio]);FILTER(dCalendario;MONTH(dCalendario[Date])<=ReportingMonth);KEEPFILTERS(fDespesas[Dispêndio]))
 
This doens't:
MySales =
VAR ReportingMonth = month(LASTDATE(fDespesas[data]))
RETURN CALCULATE(SUM(fDespesas[Dispêndio]);FILTER(dCalendario;MONTH(dCalendario[Date])<=ReportingMonth);KEEPFILTERS(fDespesas[Dispêndio]))
 
This "month(LASTDATE(fDespesas[data]))" in a measure returns 5 but using "VAR ReportingMonth = 5" works also.
 
This variable is accepting only a constant to work fine.
 
I don't want to put a 5 but want the DAX to calculate that 5.
 
Any solution?
1 ACCEPTED SOLUTION

Accepted Solutions
Super User II
Super User II

Re: VAR works with a constant date but not in a formula

If you try the following measure in your scenario what result do you get?
MySales =
VAR ReportingMonth = month(LASTDATE(fDespesas[data]))
RETURN
ReportingMonth

Not sure if it might work with MAX? https://www.sqlbi.com/blog/marco/2013/10/22/difference-between-lastdate-and-max-for-semi-additive-me...

 


______________


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


excelwithallison.com

View solution in original post

5 REPLIES 5
Super User II
Super User II

Re: VAR works with a constant date but not in a formula

If you try the following measure in your scenario what result do you get?
MySales =
VAR ReportingMonth = month(LASTDATE(fDespesas[data]))
RETURN
ReportingMonth

Not sure if it might work with MAX? https://www.sqlbi.com/blog/marco/2013/10/22/difference-between-lastdate-and-max-for-semi-additive-me...

 


______________


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


excelwithallison.com

View solution in original post

Highlighted
Super User IV
Super User IV

Re: VAR works with a constant date but not in a formula

@kkondarzewski , Try this

MySales =
VAR ReportingMonth = month(maxx(allselected(fDespesas),fDespesas[data]))
RETURN CALCULATE(SUM(fDespesas[Dispêndio]);FILTER(dCalendario;MONTH(dCalendario[Date])<=ReportingMonth);KEEPFILTERS(fDespesas[Dispêndio]))

 

or

 


MySales =
VAR ReportingMonth = calculate(month(LASTDATE(fDespesas[data])))
RETURN CALCULATE(SUM(fDespesas[Dispêndio]);FILTER(dCalendario;MONTH(dCalendario[Date])<=ReportingMonth);KEEPFILTERS(fDespesas[Dispêndio]))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
New Member

Re: VAR works with a constant date but not in a formula

It worked with MAXX

 

Thanks!

Highlighted
New Member

Re: VAR works with a constant date but not in a formula

It worked only with MAXX. Calculate brought the same as month_Lastdate.

Highlighted
Community Support
Community Support

Re: VAR works with a constant date but not in a formula

Hi @kkondarzewski ,

 

Glad to hear the problem has been solved. You may help accept the replies making sense as solution above. Your contribution is highly appreciated.

 

 

Best Regards,

Icey

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors