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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LLP515
New Member

How to get the Max of a Summed value based on another Column

Hi 

 

Need assistance I am trying to find the Max based on another column although I want the values to be summed depending on the depots filtered.

 

Example Data

DepotDate TimeValue 1Value 2
CAL18-Aug10:00AM100
CAL18-Aug11:00AM101
CAL18-Aug12:00PM202
CAL18-Aug1:00PM209
CAL18-Aug2:00PM153
MARC18-Aug10:00AM113
MARC18-Aug11:00AM154
MARC18-Aug12:00PM211
MARC18-Aug1:00PM217
MARC18-Aug2:00PM38
CAL19-Aug10:00AM102
CAL19-Aug11:00AM104
CAL19-Aug12:00PM201
CAL19-Aug1:00PM208
CAL19-Aug2:00PM153
MARC19-Aug10:00AM112
MARC19-Aug11:00AM151
MARC19-Aug12:00PM212
MARC19-Aug1:00PM215
MARC19-Aug2:00PM30

 

 

At a total level return Value 2  based on the Max Value 1. These Values should be summed if multiple depots are filtered.

 

What I am trying to acheive in a matrix with a depot filter

 Date TimeValue 1Value 2
 18-Aug10:00AM213
 18-Aug11:00AM255
 18-Aug12:00PM413
 18-Aug1:00PM4116
 18-Aug2:00PM1811
Total18-Aug 4116
 19-Aug10:00AM214
 19-Aug11:00AM255
 19-Aug12:00PM413
 19-Aug1:00PM4113
 19-Aug2:00PM183
Total19-Aug 4113
3 ACCEPTED SOLUTIONS
bhanu_gautam
Super User
Super User

@LLP515 , First create a measure for MAX Value 1

MaxValue1 =
   CALCULATE(
       MAX('Table'[Value 1]),
       ALLEXCEPT('Table', 'Table'[Date], 'Table'[Time])
   )
 
Then for Corresponding Value 2
CorrespondingValue2 =
   CALCULATE(
       SUMX(
           FILTER(
               'Table',
               'Table'[Value 1] = [MaxValue1] &&
               'Table'[Date] = EARLIER('Table'[Date]) &&
               'Table'[Time] = EARLIER('Table'[Time])
           ),
           'Table'[Value 2]
       ),
       ALLEXCEPT('Table', 'Table'[Date], 'Table'[Time])
   )
 
Similarly for total value 1 and 2
TotalMaxValue1 =
   CALCULATE(
       MAX('Table'[Value 1]),
       ALLEXCEPT('Table', 'Table'[Date])
   )
 
 TotalCorrespondingValue2 =
   CALCULATE(
       SUMX(
           FILTER(
               'Table',
               'Table'[Value 1] = [TotalMaxValue1] &&
               'Table'[Date] = EARLIER('Table'[Date])
           ),
           'Table'[Value 2]
       ),
       ALLEXCEPT('Table', 'Table'[Date])
   )
 
Add a matrix visual to your report.
Drag Date and Time to the rows.
Drag the measures MaxValue1 and CorrespondingValue2 to the values.
To show the totals, ensure that the matrix visual is set to show row totals.
Add a slicer for Depot column



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

Anonymous
Not applicable

Hi @LLP515 ,

 

Thanks bhanu_gautam  for the quick reply. I have some other thoughts to add:

(1)We can create measures.

Measure1 = CALCULATE(SUM('Table'[Value 1]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])))
Value1 = 
var _a=CALCULATE(SUM('Table'[Value 1]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])))
var _b=MAXX(FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])),[Measure1])
var _c=IF(ISINSCOPE('Table'[Time])=FALSE(),_b,_a)
RETURN _c
Value2 = 
var _a=SUM('Table'[Value 2])
var _max=MAXX(FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])),[Measure1])
var _b=CALCULATE(MAX('Table'[Time]),FILTER(ALLSELECTED('Table'),[Time] in VALUES('Table'[Time]) && [Date ] in VALUES('Table'[Date ]) && [Measure1]=_max))

var _f=CALCULATE(SUM('Table'[Value 2]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] = _b))
RETURN IF(ISINSCOPE('Table'[Time])=FALSE(),_f,_a)

(2) Then the result is as follows.

vtangjiemsft_0-1723017582923.png

Best Regards,

Neeko Tang

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

View solution in original post

Thank you! @Anonymous 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @LLP515 ,

 

Thanks bhanu_gautam  for the quick reply. I have some other thoughts to add:

(1)We can create measures.

Measure1 = CALCULATE(SUM('Table'[Value 1]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])))
Value1 = 
var _a=CALCULATE(SUM('Table'[Value 1]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])))
var _b=MAXX(FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])),[Measure1])
var _c=IF(ISINSCOPE('Table'[Time])=FALSE(),_b,_a)
RETURN _c
Value2 = 
var _a=SUM('Table'[Value 2])
var _max=MAXX(FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] in VALUES('Table'[Time])),[Measure1])
var _b=CALCULATE(MAX('Table'[Time]),FILTER(ALLSELECTED('Table'),[Time] in VALUES('Table'[Time]) && [Date ] in VALUES('Table'[Date ]) && [Measure1]=_max))

var _f=CALCULATE(SUM('Table'[Value 2]),FILTER(ALLSELECTED('Table'),[Date ] in VALUES('Table'[Date ]) && [Time] = _b))
RETURN IF(ISINSCOPE('Table'[Time])=FALSE(),_f,_a)

(2) Then the result is as follows.

vtangjiemsft_0-1723017582923.png

Best Regards,

Neeko Tang

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

Thank you! @Anonymous 

bhanu_gautam
Super User
Super User

@LLP515 , First create a measure for MAX Value 1

MaxValue1 =
   CALCULATE(
       MAX('Table'[Value 1]),
       ALLEXCEPT('Table', 'Table'[Date], 'Table'[Time])
   )
 
Then for Corresponding Value 2
CorrespondingValue2 =
   CALCULATE(
       SUMX(
           FILTER(
               'Table',
               'Table'[Value 1] = [MaxValue1] &&
               'Table'[Date] = EARLIER('Table'[Date]) &&
               'Table'[Time] = EARLIER('Table'[Time])
           ),
           'Table'[Value 2]
       ),
       ALLEXCEPT('Table', 'Table'[Date], 'Table'[Time])
   )
 
Similarly for total value 1 and 2
TotalMaxValue1 =
   CALCULATE(
       MAX('Table'[Value 1]),
       ALLEXCEPT('Table', 'Table'[Date])
   )
 
 TotalCorrespondingValue2 =
   CALCULATE(
       SUMX(
           FILTER(
               'Table',
               'Table'[Value 1] = [TotalMaxValue1] &&
               'Table'[Date] = EARLIER('Table'[Date])
           ),
           'Table'[Value 2]
       ),
       ALLEXCEPT('Table', 'Table'[Date])
   )
 
Add a matrix visual to your report.
Drag Date and Time to the rows.
Drag the measures MaxValue1 and CorrespondingValue2 to the values.
To show the totals, ensure that the matrix visual is set to show row totals.
Add a slicer for Depot column



Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.