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

Calculate - Sum with Multiple Criteria

Hello,

 

I am working on a rather tricky SQL table (see below) and now I am in a pickle.

 

I am trying to get the total hours without adding the values before the latest CARRYFORWARD action (11/25/2019).  The formula goes: Row 10 plus Row 11 to 14 minus Row 15. The result should be 277.63. It would be great if the measure can work with a slicer.

 

Thank you so much!

 

image.png

 

 

 

 

 

 

 

 

 

 

 

Data Source:

 

Row NumberAccrual TypeEffective DateActionHours
1Banked Time11/11/2019CARRYFORWARD181.88
2Banked Time15/11/2019GRANT6.75
3Banked Time17/11/2019GRANT21.00
4Banked Time18/11/2019GRANT10.50
5Banked Time19/11/2019GRANT6.00
6Banked Time20/11/2019GRANT11.25
7Banked Time21/11/2019GRANT6.00
8Banked Time22/11/2019GRANT12.00
9Banked Time24/11/2019GRANT17.25
10Banked Time25/11/2019CARRYFORWARD272.63
11Banked Time25/11/2019GRANT3.00
12Banked Time26/11/2019GRANT4.50
13Banked Time27/11/2019GRANT3.00
14Banked Time28/11/2019GRANT1.50
15Banked Time29/11/2019TAKEN-7.00

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Perhaps something along the lines of:

 

Measure = 
  VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Row Number])
RETURN
  SUMX(FILTER('Table',[Row Number] >= __Max),[Hours])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

Perhaps something along the lines of:

 

Measure = 
  VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Row Number])
RETURN
  SUMX(FILTER('Table',[Row Number] >= __Max),[Hours])

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you for this!

 

I ended up splitting the table and changed the formula a little bit and added a USERELATIONSHIP so I can limit the max date according to my slicer.

 

 

Measure = 
  VAR __Max = MAXX(FILTER('Table',[Action] = "CARRYFORWARD"),[Effective Date])
RETURN
  CALCULATE(SUMX(FILTER('Table',[Effective Date] >= __Max),[Hours]), USERELATIONSHIP([Effective Date],DateDim[Date]))      

 

 

Thanks again!

 

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.