The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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] ) )
Sum of max values = SUMX(
ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[Date], 'Table'[Location]), "@val",
CALCULATE( MAX( 'Table'[Value])) ),
[@val] )
User | Count |
---|---|
28 | |
10 | |
8 | |
6 | |
5 |
User | Count |
---|---|
34 | |
13 | |
12 | |
9 | |
7 |