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

calculate sum till date selected

Dear team, 

 

Please help me with problem scenario:

 

Date(dd/mm/yyyy)                     Sales 

1/1/2020                                      50

2/1/2020                                      60

3/1/2020                                      80

4/1/2020                                      45

5/1/2020                                      70

 

Case 1: If user selects date as 3/1/2020: then it should display sales sum till 3/1/2020  ( 50+60+80) = 190

Case 2:  if user selects a date range ( 1/1/2020-4/1/2020). then it should add sales value end date range, i.e. till 4/1/2020 = (50+60+80+45) = 235

 

 

Problem 2:

As per the above data, if user selects a date, it should tell me how many days have passed in year till that date(including that date)

For example, if user selects 10/1/2020), value should be 10 Days 

 

b)if user selects date range, then number of days passed till end date range should be displayed

Example : 2/1/2020- 8/1/2020 

then display 8Days  as per 8/1/2020

 

Thanks in advance!

1 ACCEPTED SOLUTION

@Anonymous ,

 

Yes. Based on my test it will.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

8 REPLIES 8
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

Check this measure.

Measure = 
var a = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])))
var b = CALCULATE(SUM('Table'[Sales]),FILTER(ALL('Table'),'Table'[Date]<=MAX('Table'[Date])&&'Table'[Date]>=MIN('Table'[Date])))
return
IF(COUNTROWS('Table')=1,a,b)

Result would be shown as below.

 4.PNG5.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

@v-jayw-msft 

Thankyou will try this once and share my feedback.

 

If possible share the solution for second half of my question as well that how to find the number of day from a respective date

For example:

5/1/2020 - 5th Day

29/12/2020 - 364th Day

A logic which tells how many days have passed including the date which has been selected.

 

Thankyou

Hi @Anonymous ,

 

Check this measure for your second question.

Measure = 
var mindate = CALCULATE(MIN('Table'[date]),ALL('Table'))
return
IF(COUNTROWS('Table')=1,DATEDIFF(mindate,SELECTEDVALUE('Table'[date]),DAY)+1,DATEDIFF(MIN('Table'[date]),MAX('Table'[date]),DAY)+1)

Result as below.

7.PNG 6.PNG

 

Best Regards,

Jay

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

I have a similar question.  i am trying to sum the "# of day selected".  I tried this formula you commented, but it did not work for me ... 

 

Measure = var mindate = CALCULATE(MIN('Table'[date]),ALL('Table')) return IF(COUNTROWS('Table')=1,DATEDIFF(mindate,SELECTEDVALUE('Table'[date]),DAY)+1,DATEDIFF(MIN('Table'[date]),MAX('Table'[date]),DAY)+1)

 

jonnyA_0-1658849807842.png

 

Anonymous
Not applicable

@v-jayw-msft 

 

Will this logic works if I have 2 year of date? 2019 and 2020

@Anonymous ,

 

Yes. Based on my test it will.

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
amitchandak
Super User
Super User

@Anonymous , for first one . Try with a date table

 

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(date,date[date] <=maxx(date,date[date])))
Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(date,date[date] <=max(Sales[Sales Date])))

 

or

Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=maxx(date,date[date])))
Cumm Sales = CALCULATE(SUM(Sales[Sales Amount]),filter(allselected(date),date[date] <=max(Sales[Sales Date])))

 

second one

days measure =

var _max =selectedvalue(Date[Date])

return

datediff( date(year(_max) ,1,1), _max , Day)

 

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/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

 

Anonymous
Not applicable

c1.PNG
 
for second part, I tried this but my measure is showing blank value .What am I missing here ?
 
I have calendar table only which shows month and year.
 
Please help me 

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.