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
mespoKTM
Regular Visitor

Calculate sum with rolling data filter

I have a measure that calculates the end of the month based on the month selected in a histogram chart. I need to calculate a sum for documents that have as date the period between the beginning of the year and the calculated date.

 

This is the Sum measure:

99_FatturatoYTD = CALCULATE(SUM(Fatturato_No_ArticoliNulli[DO30_IMPORTO]),
FILTER(ALL(Fatturato_No_ArticoliNulli),
AND(Fatturato_No_ArticoliNulli[DO11_DATADOC]>=DATE(YEAR(NOW()),01,01),
Fatturato_No_ArticoliNulli[DO11_DATADOC]<=[99_EOMONTH_SELVALUE])))

This is the Data measure:
99_EOMONTH_SELVALUE = EOMONTH(DATE(YEAR(NOW()),LEFT(SELECTEDVALUE(Mesi[Mesi]),2),01),0)
 
If substitute the measure with the exact date it works
4 REPLIES 4
v-deddai1-msft
Community Support
Community Support

Hi @mespoKTM ,

 

If you don't select any bar or select mulitiple bars in histogram chart,  SELECTEDVALUE(Mesi[Mesi]) will not get blank value in your formula, you should use SELECTEDVALUE(Mesi[Mesi],"12") in your formula  to show value  when the context for columnName has been filtered down to zero or more than one distinct value. 

 

For more details, please refer to https://docs.microsoft.com/en-us/dax/selectedvalue-function

 

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

 

Best Regards,

Dedmon Dai

amitchandak
Super User
Super User

@mespoKTM , Not very clear. But if you have date, You can use time intelligence and date table

 

example

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"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

I'm sorry but your solution doesn't works.

I simply want to calculate the sum of revenue from the start of the year to the end of selected month.

 

Thank you so much!

Hi @mespoKTM ,

 

I suggest you use lastnonblank instead of selectedvalue in your formula:

 

99_EOMONTH_SELVALUE = EOMONTH(DATE(YEAR(NOW()),LEFT(LASTNONBLANK(Mesi[Mesi],1),2),01),0)

 

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

 

Best Regards,

Dedmon Dai

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.

Top Solution Authors