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
Rob92
Frequent Visitor

Conditional Measure using slicer selection

I am trying to put together a stacked column chart, using the example table below, I want to show total transactions per month. The one color of the stacked column will show transactions by clients who joined before the start of the selected date range (marked those in bold below), and the other color of the bar will be transactions by clients who joined after the start of the selected date range (marked those in italics below).  The user needs the ability to chose the date range with a slice.  In this example let's say the user has chosen 1/1/24 - 3/31/24.  So the Jan column would show a total of 18 transactions (16 from old clients, 2 from new), Feb would show 24 transactions (14 from old clients, 10 from new), and Mar would show 33 transactions (13 from old clients, 20 from new).

 

If the user changes the date range, the clients that are considered old or new will change.  Here if they changed the range to 2/1/24 - 3/31/24, then client C would change from the new catagory to old.

 

Since the user needs control of the date range, I can't code these catagories into the datasource. I know I can't reference a single slicer value in a calculated column formula.  So I'm trying to figure out if I can achieve this with a measure, using SWITCH and SELECTEDVALUE to check if a Client_joined date is before or after the start of the date range the user sets, and catagorize the transactions in the visual dynamically that way. Any thoughts on this?  Or any other ways I could achieve this result?  Thanks in advance!

 

ClientClient_joinedTransactionsTransaction_month
A5/5/20239Jan-24
B10/10/20237Jan-24
C1/20/20242Jan-24
A5/5/20238Feb-24
B10/10/20236Feb-24
C1/20/20247Feb-24
D2/15/20243Feb-24
A5/5/20238Mar-24
B10/10/20235Mar-24
C1/20/20246Mar-24
D2/15/20248Mar-24
E3/5/20246Mar-24
2 ACCEPTED SOLUTIONS
v-yiruan-msft
Community Support
Community Support

Hi @Rob92 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a sperated date dimension table(DO NOT create any relationship with your fact table) just as suggested by Ibendlin

vyiruanmsft_1-1723699553307.png

2. Create two measures as below

Old clients count = 
VAR _mindate =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Transactions] ),
        FILTER ( 'Table', 'Table'[Client_joined] <= _mindate )
    )
New clients count = 
VAR _mindate =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Transactions] ),
        FILTER ( 'Table', 'Table'[Client_joined] > _mindate )
    )

3. Create a table visual as shown in the below screenshot

vyiruanmsft_0-1723699463902.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Rob92
Frequent Visitor

Awesome, thanks guys!  I have implemented the solution on my real data and it works a treat.  The only issue was that as well as the slicer controlling which users are new or old, I also need it to filter the visual.  In order to do this I have joined the date dimension table to the fact table.  This causes the date hierachy to break but that's not a problem - to resolve that, I added separate month and year columns in power query, and used those on the X axis instead.  Problem solved!

 

Rob92_0-1723720609172.png

 

View solution in original post

3 REPLIES 3
Rob92
Frequent Visitor

Awesome, thanks guys!  I have implemented the solution on my real data and it works a treat.  The only issue was that as well as the slicer controlling which users are new or old, I also need it to filter the visual.  In order to do this I have joined the date dimension table to the fact table.  This causes the date hierachy to break but that's not a problem - to resolve that, I added separate month and year columns in power query, and used those on the X axis instead.  Problem solved!

 

Rob92_0-1723720609172.png

 

v-yiruan-msft
Community Support
Community Support

Hi @Rob92 ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a sperated date dimension table(DO NOT create any relationship with your fact table) just as suggested by Ibendlin

vyiruanmsft_1-1723699553307.png

2. Create two measures as below

Old clients count = 
VAR _mindate =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Transactions] ),
        FILTER ( 'Table', 'Table'[Client_joined] <= _mindate )
    )
New clients count = 
VAR _mindate =
    MIN ( 'Date'[Date] )
RETURN
    CALCULATE (
        SUM ( 'Table'[Transactions] ),
        FILTER ( 'Table', 'Table'[Client_joined] > _mindate )
    )

3. Create a table visual as shown in the below screenshot

vyiruanmsft_0-1723699463902.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin
Super User
Super User

You need to use a disconnected table to feed your date range slicer, and then use measures to filter your visual.

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.