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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sum previous year

Hi,

that's my graph:

image.png

 

With the blue line (that's a simply distinct count) i need to sum the previous year to the current year.

 

So, it will become:

 

2014: 819

2015: 2412 + (819)

2016: 1702 + (2412 + 819)

....

 

How can i achieve this?

 

Thanks for help

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@Anonymous 

try a measure

Measure = CALCULATE(SUM('Table'[Codici]),FILTER(ALL('Table'),'Table'[Year]<=MAX('Table'[Year])))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

12 REPLIES 12
amitchandak
Super User
Super User

If you have date dimension, you can try datesytd

YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
2 Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-2,Year))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Proud to be a Datanaut Connect on Linkedin

Really useful and concise YTD measures, thank you.

Anonymous
Not applicable

How would you go about this if "Sales[Sales Amount]" was a measure? 

az38
Community Champion
Community Champion

Hi @Anonymous 

If "Codici" are exist in both 2019 and 2018 years it should be calculated as 1 or as 2?


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi,

it should be count as 2!

 

Thanks

Anonymous
Not applicable

mid-question

image.pngimage.png

 

these 2 columns are the same format: data type.

 

Why BI show me only one like a hierarchy?

 

az38
Community Champion
Community Champion

@Anonymous 

I think its because "Valido da" field is not clean, maybe it has an error values. check it in source and Power QUery editor. If everything is ok, set data type as date in Power query editor mode


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
az38
Community Champion
Community Champion

@Anonymous 

try a measure

Measure = CALCULATE(SUM('Table'[Codici]),FILTER(ALL('Table'),'Table'[Year]<=MAX('Table'[Year])))

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

I got the desired values with the above solution . Now when i am putting legends the graph is showing same values 
Please if you have any solution on this 

Anonymous
Not applicable

image.png

Am i missing something?

Anonymous
Not applicable

This is the problem

image.png

 

in the measure ALL is a problem

 

I will try with allexcept

 

 

Anonymous
Not applicable

image.pngimage.png

 

Ok thanks it works with some correction in the filter, thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.