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
bingbadabom
Helper I
Helper I

Sum the sum of values for first and last date

I have a table that looks like this. The values presented here are filtered with a slicer.

I would like to sum the values for the first date (feb 19th) and the last date (feb 22nd). I've tried adapting solutions i've found for almost similar problems but with no luck.

 

bingbadabom_0-1614260696175.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@bingbadabom , Try a measure like

 


measure =
var _max = maxx(allselected(Table), Table[Date])
var _min = maxx(allselected(Table), Table[Date])
return
calculate(sum(Table[value]), filter(Table, Table[Date] =_min || Table[Date] =_max))

View solution in original post

5 REPLIES 5
v-yuaj-msft
Community Support
Community Support

Hi @bingbadabom ,

 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Yuna

 

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

v-yuaj-msft
Community Support
Community Support

Hi @bingbadabom ,

 

Based on your description, you can create some measures as follows.

_sum = 

var selected_max=MAXX(ALLSELECTED('Table'),[date])

var selected_min=MINX(ALLSELECTED('Table'),[date])

return

SUMX(FILTER(ALL('Table'),[date] in {selected_min,selected_max}),[value])
_subtract = 

var selected_max=MAXX(ALLSELECTED('Table'),[date])

var selected_min=MINX(ALLSELECTED('Table'),[date])

var x1=SUMX(FILTER(ALL('Table'),[date]=selected_min),[value])

var x2=SUMX(FILTER(ALL('Table'),[date]=selected_max),[value])

return

x1-x2

Result:

v-yuaj-msft_0-1614568725526.png

 

Hope that's what you were looking for.

Best Regards,

Yuna

 

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

 

amitchandak
Super User
Super User

@bingbadabom , Try a measure like

 


measure =
var _max = maxx(allselected(Table), Table[Date])
var _min = maxx(allselected(Table), Table[Date])
return
calculate(sum(Table[value]), filter(Table, Table[Date] =_min || Table[Date] =_max))

This helped me a lot by the way. Thank you.
But if i need to sum each date by itself and subtract the two numbers?

calculate(
    sum('Table'[Value]), filter('Table', 'Table'[Date] =_min) 
    -
    sum('Table'[Value]), filter('Table', 'Table'[Date] =_max)
)

I get the following error message "A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

 

_max and _min returns the same date. I tried replacing MAXX with MINX but then the date went too far back, it seems that it does not take the slicer values into account

Edit:
This took care of my date problems

var _max = CALCULATE(LASTDATE('Table[Date]), ALLSELECTED('Table[Date]))
var _min = CALCULATE(FIRSTDATE('Table[Date]), ALLSELECTED('Table[Date]))
 

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.