March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
115 | |
76 | |
57 | |
52 | |
44 |
User | Count |
---|---|
164 | |
116 | |
63 | |
57 | |
50 |