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

Be 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

Reply
Anonymous
Not applicable

Calculate a Metric for Date Range + Latest Week in Same Matrix

I have a report I have been working on to calculate overtime for departments/supervisors/employees. I can create two separate matrix visuals with the latest week OT% (using TopN visual level filter) and one that has all the weeks and the OT%. The problem is I need this in a single matrix so that the user can see the OT% for the latest week selected vs. the OT% for all the weeks in the selected date range - this would help them determine if this week is an isolated incident or a common OT% for that area (e.g. higher than the average OT% for the weeks selected).

 

No matter what I try (ALL, ALLEXCEPT, ALLSELECTED, VALUES, etc.) I cannot combine these two measures into a single matrix! If anyone can provide some help I would be forever grateful (well maybe not forever, but at least for a little while...).

 

The PBIX and a sample XLSX source are located here:

https://drive.google.com/drive/folders/15VBBeneWtf7KGDhmdoXPTy12-WEiQQyH

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Let's see if this gets us in the right direction.

 

First thing I did was make separate measures to use in more complex code.  Call these "Base Measures", which is how I was taught:

Total OverTime = 
	SUM ( DataForPBIX[OT Amt])

Total NonOvertime = 
	SUM ( DataForPBIX[NonOT Amt])

Total OT + NonOT = 
[Total Overtime] + [Total NonOvertime]

OverTime % = 
DIVIDE( [Total OverTime],[Total OT + NonOT])

With those in place, had to figure out a way to filter the date in your table.  Decided to go with a parameter table.  

Disconnected Week Table = VALUES('DataForPBIX'[week])

The resulting table:

Discon Table.png

This will be used to create virtual relationships.  Using that table, we add a filter to the canvas:

Disc Filter.png

Then we create a measure to grab the min and max of those values:

Min of Week Selected = min ( 'Disconnected Week Table'[Week])

Max of Week Selected = MAX( 'Disconnected Week Table'[Week])

RANGE SELECTED = [Min of Week Selected]& " to " &  [Max of Week Selected]

Min Max of Range.png

 

Create a measure to give the Overtime % of the max of the selected:

Latest Week Selected % = 
CALCULATE(
	[OverTime %],
	FILTER(
		 ALL(DataForPBIX[Week]),
		 'DataForPBIX'[Week] = [Max of Week Selected] 
    )
) 

Then create a measure that uses the entire range of the user selected:

Range Selected % = 
CALCULATE(
	[OverTime %],
	FILTER(
		 ALL(DataForPBIX[Week]),
		 DataForPBIX[Week] <= [Max of Week Selected]
		 	&& DataForPBIX[Week] >= [Min of Week Selected]
    )
) 

Create a Delta measure that simply subtracts the latest week select OT% and the OT % of the entire selected range:

Delta = [Latest Week Selected %] -[Range Selected %]

Then thought creating a rank from that delta could be interesting:

Rank of Delta = 
RANKX(
		 ALL(DataForPBIX[DeptR]),
         [Delta],,
         DESC,
         Skip
) 

Table with all those (which may or may not be overkill to show...)

Final Table.png

 

Building on that idea, created another measure that will be a table that shows only the Delta for Top "x"

TopN of Delta = 
IF(
	ISFILTERED( DataForPBIX[DeptR]),
	IF ([Rank of Delta] <= 10, [Delta],BLANK()))

So instead of seeing the entire table, only see the Top 10 in this case.  But could make it dynamic using the parameter/disconnected table method I used above:

Topn Table.png

 

There would still need to be further testing and such as there could be situations where the above formulas won't work.  All depends on the initial filter context really, especially for RANKX.  I do think it's a good step in the right direction. 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Let's see if this gets us in the right direction.

 

First thing I did was make separate measures to use in more complex code.  Call these "Base Measures", which is how I was taught:

Total OverTime = 
	SUM ( DataForPBIX[OT Amt])

Total NonOvertime = 
	SUM ( DataForPBIX[NonOT Amt])

Total OT + NonOT = 
[Total Overtime] + [Total NonOvertime]

OverTime % = 
DIVIDE( [Total OverTime],[Total OT + NonOT])

With those in place, had to figure out a way to filter the date in your table.  Decided to go with a parameter table.  

Disconnected Week Table = VALUES('DataForPBIX'[week])

The resulting table:

Discon Table.png

This will be used to create virtual relationships.  Using that table, we add a filter to the canvas:

Disc Filter.png

Then we create a measure to grab the min and max of those values:

Min of Week Selected = min ( 'Disconnected Week Table'[Week])

Max of Week Selected = MAX( 'Disconnected Week Table'[Week])

RANGE SELECTED = [Min of Week Selected]& " to " &  [Max of Week Selected]

Min Max of Range.png

 

Create a measure to give the Overtime % of the max of the selected:

Latest Week Selected % = 
CALCULATE(
	[OverTime %],
	FILTER(
		 ALL(DataForPBIX[Week]),
		 'DataForPBIX'[Week] = [Max of Week Selected] 
    )
) 

Then create a measure that uses the entire range of the user selected:

Range Selected % = 
CALCULATE(
	[OverTime %],
	FILTER(
		 ALL(DataForPBIX[Week]),
		 DataForPBIX[Week] <= [Max of Week Selected]
		 	&& DataForPBIX[Week] >= [Min of Week Selected]
    )
) 

Create a Delta measure that simply subtracts the latest week select OT% and the OT % of the entire selected range:

Delta = [Latest Week Selected %] -[Range Selected %]

Then thought creating a rank from that delta could be interesting:

Rank of Delta = 
RANKX(
		 ALL(DataForPBIX[DeptR]),
         [Delta],,
         DESC,
         Skip
) 

Table with all those (which may or may not be overkill to show...)

Final Table.png

 

Building on that idea, created another measure that will be a table that shows only the Delta for Top "x"

TopN of Delta = 
IF(
	ISFILTERED( DataForPBIX[DeptR]),
	IF ([Rank of Delta] <= 10, [Delta],BLANK()))

So instead of seeing the entire table, only see the Top 10 in this case.  But could make it dynamic using the parameter/disconnected table method I used above:

Topn Table.png

 

There would still need to be further testing and such as there could be situations where the above formulas won't work.  All depends on the initial filter context really, especially for RANKX.  I do think it's a good step in the right direction. 

Anonymous
Not applicable

@Anonymous- Thank you very much for the detailed response.

 

After some testing I believe this is EXACTLY what I was looking for and I greatly appreciate the help!

Anonymous
Not applicable

Awesome! Glad it helped

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.