Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I want to use DAX to calculate a daily sum of max values grouped by by date and location.
The starting data looks like the table below.
Date | Location | Value |
2022-03-01 | A | 10 |
2022-03-01 | B | 20 |
2022-03-01 | A | 30 |
2022-03-01 | B | 5 |
2022-03-02 | A | 20 |
2022-03-02 | B | 40 |
2022-03-02 | A | 5 |
2022-03-02 | B | 10 |
First step is to get max values by date and location | ||
Date | Location | Max Value |
2022-03-01 | A | 30 |
2022-03-01 | B | 20 |
2022-03-02 | A | 20 |
2022-03-02 | B | 40 |
Second step is to get sum of max values by date | ||
Date | Sum Max Value | |
2022-03-01 | 50 | |
2022-03-02 | 60 |
Can this be done in a single DAX Measure?
I already have a DAX measure that calculates a sum of max values by location:
Sum Max Location Values = SUMX( VALUES ( 'Table'[Location] ), CALCULATE( MAX( 'Table'[Values] )))
Solved! Go to Solution.
Sum of max values = SUMX(
ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[Date], 'Table'[Location]), "@val",
CALCULATE( MAX( 'Table'[Value])) ),
[@val] )
Hi,
Please check the picture down below and the attached pbix file.
One is for creating a new table, and the other is for creating a measure.
Desired table =
VAR stepone =
GROUPBY (
Data,
Data[Date],
Data[Location],
"@maxvalue", MAXX ( CURRENTGROUP (), Data[Value] )
)
VAR steptwo =
GROUPBY (
stepone,
Data[Date],
"@SumMaxValue", SUMX ( CURRENTGROUP (), [@maxvalue] )
)
RETURN
steptwo
Desired measure: =
VAR stepone =
GROUPBY (
Data,
Data[Location],
"@maxvalue", MAXX ( CURRENTGROUP (), Data[Value] )
)
RETURN
IF ( HASONEVALUE ( Data[Date] ), SUMX ( stepone, [@maxvalue] ) )
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Schedule a short Teams meeting to discuss your question
Sum of max values = SUMX(
ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[Date], 'Table'[Location]), "@val",
CALCULATE( MAX( 'Table'[Value])) ),
[@val] )
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |