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
Anonymous
Not applicable

multiple year to dates lines in one visual

Community:   Any idea how to adjust this formula so that it does not show (the previous years) beyond the current date?    As you can see, the orange value is this year and stops after there are no more values.   This is perfect.   I would like the other years to also stop at the same point in time, based on week, or month.   How would I constrain multiple dates like that based on the formula below?

 

Cumulative All Years = CALCULATE(SUM(Shipments[ShippedPrice]),FILTER(ALL(Shipments),Shipments[DateShipped]<=MAX(Shipments[DateShipped])),VALUES(Shipments[Date Shipped Year]))

 
 
 
 
 
 
 
 
 
 
 
 
 

Screenshot 2021-02-23 195323.jpg

 
 

 

 
1 ACCEPTED SOLUTION

Hi @Anonymous ,

Try the following formula:

Cumulative All Years = 
var t = 
  CALCULATE(
    SUM(Shipments[ShippedPrice]),
    FILTER(
      ALL(Shipments),
      Shipments[DateShipped] <= MAX(Shipments[DateShipped])
    ),
    VALUES(Shipments[Date Shipped Year])
  )
var result = 
  IF(
    MONTH(MAX(Shipments[DateShipped]))<=MONTH(LASTDATE(ALL(Shipments[DateShipped]))),
    t
  )
return result

image.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

4 REPLIES 4
plainly
Regular Visitor

Hello,

If you want the data to stop to a  certain month / week that is exactly what you should write to the filter.

E.g. for the month level ( you are likely to guess how to make it with && condition for  a week too):

FILTER('Calendar';'Calendar'[Month Number] <= MONTH(today()))

'Calendar'[Month Number] you can replace with MONTH(table[date])

 

See more info on how to calculate with dates: 

https://www.plainlyresults.com/blog/power-bi-dax-how-to-calculate-and-filter-based-on-dates/

 

Ashish_Mathur
Super User
Super User

Hi,

Share the link from where i can download your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

@Ashish_Mathur   Unfortunately I cannot due to sensitive data

Hi @Anonymous ,

Try the following formula:

Cumulative All Years = 
var t = 
  CALCULATE(
    SUM(Shipments[ShippedPrice]),
    FILTER(
      ALL(Shipments),
      Shipments[DateShipped] <= MAX(Shipments[DateShipped])
    ),
    VALUES(Shipments[Date Shipped Year])
  )
var result = 
  IF(
    MONTH(MAX(Shipments[DateShipped]))<=MONTH(LASTDATE(ALL(Shipments[DateShipped]))),
    t
  )
return result

image.png

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

Best Regards,
Winniz

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

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.