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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Mitchell92
Helper I
Helper I

Adding Switch Results to Matrix (or different solution)

Hi all,

 

I'm hoping someone may be able to assist.

 

I have a list of invoice #'s with invoice date and amount, and also a calendar table with a relationship between the invoice date and calendar date.

 

On the report, I want to be able to select the calendar date using a slicer, and have a table populate the age of the invoice (per selected date), and summarise the invoice amounts by an "age bracket" within a matrix.

 

I have achieved two things thus far:

1) I have been able to calculate the invoice age per selected slicer date using the following measure:

 
Age2 =
VAR _RangeStart = MIN(AR[TRXDTE])
VAR _RangeEnd = MAX(DateTable[Date])
RETURN
DATEDIFF(_RangeStart,_RangeEnd,DAY)
 

2) I have created a measure with a switch formula to distribute ages between age brackets:

 
AgeBrackets = switch( true,
[Age2] <= 30, "0 - 30", [Age2] <= 60, "31 - 60", [Age2] <= 90, "61 - 90", [Age2] < 120, "91 - 120","120+")
 
What I am unable to achieve is putting the AgeBrackets measure into a matrix as the column headers (with invoice value as values) to summarise this effectively.
 
I'm hoping someone has experience with this / may be able to assist? Hoping its a quick and easy solution.
 
PBIX LINK:
 
Thanks in advance.

 

 

 

2 REPLIES 2
DataInsights
Super User
Super User

@Mitchell92,

 

Create a disconnected table like the one below (no relationships). Sort Age Bracket by Age Bracket Index.

 

DataInsights_0-1716383071568.png

 

Create measures:

 

Sum of Total = SUM ( ARITEMA2[Total] )
AgeBrackets = 
VAR vLowerBound =
    SELECTEDVALUE ( AgeBracket[Lower Bound] )
VAR vUpperBound =
    SELECTEDVALUE ( AgeBracket[Upper Bound] )
VAR vAge = [Age2]
VAR vResult =
    IF ( vAge >= vLowerBound && vAge <= vUpperBound, [Sum of Total] )
RETURN
    vResult

 

Add AgeBracket[Age Bracket] to matrix columns, and [AgeBrackets] to matrix values. You can expand this example to handle totals with a measure like this:

 

AgeBrackets = 
VAR vLowerBound =
    SELECTEDVALUE ( AgeBracket[Lower Bound] )
VAR vUpperBound =
    SELECTEDVALUE ( AgeBracket[Upper Bound] )
VAR vAge = [Age2]
VAR vResult =
    SUMX ( VALUES ( HEADER[OPS] ), IF ( vAge >= vLowerBound && vAge <= vUpperBound, [Sum of Total] ) )
RETURN
    vResult

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @DataInsights , thank you for your assistance. This has certainly got me a lot further - I have one issue though. On my actual data set, theres about 4 years worth of invoicing. This solution seems to be lumping everything into the max bracket within the category (everything is being categorised as 120+).

 

Wondering if there is a quick solution for that?

 

Thanks in advance.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.