Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
There is a FACT table that looks something like
Date | Hour | DateTime | Name | Number |
1/19/2023 | 9 | 1/19/2023 09:00 | Brad | 50 |
1/19/2023 | 9 | 1/19/2023 09:00 | Tim | 35 |
etc etc |
How can we get the largest sum of Numbers for each month, by Date and Hour?
I currently have DIM tables for Date (from start to end of data), Hour (1 to 24), and Name.
When I create a matrix visualization of the dataset, the measure currently seems to find the largest Number as it pertains to the daily totals rather than on the per hour level.
Here is a mockup of the matrix visual and an sanitized/anonymized equivalent of the measure.
Thanks in advance for any pointers!
MaxPerMonth =
VAR IsPartOfCalculations =
IF (
[Number]
<> BLANK (),
1,
0
)
VAR MaxDate =
CALCULATE (
MAXX (
TOPN (
1,
DIM_Dates,
[Number], DESC
),
DIM_Dates[Date]
),
REMOVEFILTERS ( DIM_Names ),
REMOVEFILTERS ( DIM_Dates[Day] ),
REMOVEFILTERS ( DIM_Hours[Hour] )
)
VAR MaxNumber =
CALCULATE (
MAXX (
TOPN (
1,
DIM_Dates,
[Number], DESC
),
[Number]
),
FILTER (
DIM_Dates,
DIM_Dates[Date] = MaxDate
),
REMOVEFILTERS ( DIM_Dates[Day] ),
REMOVEFILTERS ( DIM_Hours[Hour] )
)
VAR Result =
IF (
IsPartOfCalculations,
MaxNumber,
BLANK ()
)
RETURN
Result
---
EDIT: Update formatting
Solved! Go to Solution.
I made some progress by drastically simplifying the MAXX measure.
If the visual matrix is limited to the Year and Month, this gets the proper MAXX total
For the month of January, let's say the highest sum of Numbers for any given date time is this one, @ $27
Now that I know what the highest total number is across January, how do I get the DateTime that's associated with that $27 value?
MaxDate =
VAR Number =
CALCULATE(
MAXX(
VALUES( FACT_Table[DateTime] ),
[Number]
)
)
VAR Result =
CALCULATE(
MAX( DIM_Dates[Date] ),
FILTER(
ALL( DIM_Dates ),
[MaxNumber] = Number
)
)
RETURN
Result
Similar for the Hour.
Then, to combine them into a DateTime I used
VAR MaxDate =
[MaxDate]
VAR MaxTime =
TIME([MaxHour], 0, 0)
VAR MaxDateTime =
MaxDate + TIME( HOUR( MaxTime ), MINUTE( MaxTime ), SECOND( MaxTime ) )
VAR Result =
MaxDateTime
RETURN
Result
I made some progress by drastically simplifying the MAXX measure.
If the visual matrix is limited to the Year and Month, this gets the proper MAXX total
For the month of January, let's say the highest sum of Numbers for any given date time is this one, @ $27
Now that I know what the highest total number is across January, how do I get the DateTime that's associated with that $27 value?
MaxDate =
VAR Number =
CALCULATE(
MAXX(
VALUES( FACT_Table[DateTime] ),
[Number]
)
)
VAR Result =
CALCULATE(
MAX( DIM_Dates[Date] ),
FILTER(
ALL( DIM_Dates ),
[MaxNumber] = Number
)
)
RETURN
Result
Similar for the Hour.
Then, to combine them into a DateTime I used
VAR MaxDate =
[MaxDate]
VAR MaxTime =
TIME([MaxHour], 0, 0)
VAR MaxDateTime =
MaxDate + TIME( HOUR( MaxTime ), MINUTE( MaxTime ), SECOND( MaxTime ) )
VAR Result =
MaxDateTime
RETURN
Result
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
90 | |
84 | |
70 | |
49 |
User | Count |
---|---|
143 | |
121 | |
112 | |
59 | |
58 |