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
KW123
Helper V
Helper V

Year Diff with Slicer

Hi, 

I have a column that shows the year difference between opening and account and closing the account.  I'd like to make a slicer which has the following options 

SLICER:
<1 year
1-3 years
3-5 years
>5 Years 

Is there a way to create a slicer that could show this? 

1 ACCEPTED SOLUTION

Hi , 

How about this:

SWITCH (
    TRUE,
    'Query1'[Year Diff] < 1,"<1",
    'Query1'[Year Diff] >= 1 && 'Query1'[Year Diff] <= 3,"1-3",
    'Query1'[Year Diff] >= 4 && 'Query1'[Year Diff] <= 5,"4-5",
    ">5"
)


/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 

@KW123



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

6 REPLIES 6
tackytechtom
Super User
Super User

Hi @KW123 ,

 

I'd suggest you add a new column with the logic above to create the bins you need. 

 

Then use that column in your slicer. 

 

Try to create the column as upstream as possible and as downstream as necessary, meaning add the column in the source if possible. If that does not work do it rather in Power Query as in DAX.

 

Let me know if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

@tackytechtom 

Thank you.  I am not sure how to do that. 

@KW123 ,

 

Create a new column with an if statement where you implement your logic like

if table[YearDifference] < 1 then "<1 year" else

if table[YearDifference] >= 1 and table[YearDifference] < 3 then "1-3 years" else 

if table[YearDifference] >= 3 and table[YearDifference] < 5 then "3-5 years" else

">5 Years "

Note, the code above is just a pseudo code. You have to google the right syntax yourself depending on whether you are using DAX code or Power Query's M.

 

Does this help? 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

@tackytechtom 

if ('Query1'[Year Diff] <1,"<1",
if ('Query1'[Year Diff] = 1 || 2 || 3, "1-3",
if ('Query1'[Year Diff] = 4 || 5 ,"4-5",
if ('Query1'[Year Diff] >5, ">5"))))
I have that but I am not sure where to put the ELSE.  It seems as though the DAX works for <1 and 1-3 but it is not producing the 4-5 or >5 


Hi , 

How about this:

SWITCH (
    TRUE,
    'Query1'[Year Diff] < 1,"<1",
    'Query1'[Year Diff] >= 1 && 'Query1'[Year Diff] <= 3,"1-3",
    'Query1'[Year Diff] >= 4 && 'Query1'[Year Diff] <= 5,"4-5",
    ">5"
)


/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 

@KW123



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

@tackytechtom 

Thank you so much, this is exactly what I am looking for! 

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.