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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Solle
Helper III
Helper III

Grouped by time to maturity with between slicer

Hi all, 

I have a table which requires me to group by time to maturity. This is done directly in Power Query where the "TimeToMaturity" is calculated by subtracting "As Of Date" with "MaturityDate". After this I have grouped them by adding a column named "MaturityBucketName" and "MaturityBucketID" with an if statement based on the column "TimeToMaturity" in the following categories:

MaturityBucketNameMaturityBucketID

Under 2.25 years to maturity

1

Between 2.25 and 3.25 years to maturity

2

Above 3.25 years to maturity

3

 

In my report all contracts is then grouped by these in a matrix, which consists of the following rows:

  • MaturityBucketName
  • ContractID

Then on the same page I have some other timeseries data, which is calculated using a between slicer, which also affects my ContractIDs as when they change groups in my grouping data, they are getting duplicated, so the same contract is now both in i.e. Between 2.25 and 3.25 years to maturity and under 2.25 years to maturity. 

Does anyone know how to solve this issue, I have tried generating this in DAX with a max function on date, but it does not allow me to apply it on the row level? 

Best Regards.

 

1 ACCEPTED SOLUTION
Sahir_Maharaj
Super User
Super User

Hello @Solle,

 

Can you please try this:

 

  1. In Power Query, instead of directly calculating "TimeToMaturity" as a column, consider creating a calculated column that determines the "MaturityBucketID" based on the original "MaturityDate" and "As Of Date" columns.

  2. This calculated column should be assigned based on the criteria you specified (Under 2.25, Between 2.25 and 3.25, Above 3.25), using IF statements or custom functions.

  3. Create a measure that calculates the maximum "MaturityBucketID" for each ContractID based on the filtered time range from the slicer. When you're creating your matrix with "MaturityBucketName" and "ContractID" as rows, use the "MaxMaturityBucketID" measure as the values.

 

MaxMaturityBucketID = 
CALCULATE(
    MAX('YourTable'[MaturityBucketID]),
    ALLSELECTED('YourTable'),
    'YourTable'[As Of Date] >= MIN('DateSlicer'[StartDate]) &&
    'YourTable'[As Of Date] <= MAX('DateSlicer'[EndDate])
)

 

 

Should you require further details or information, please do not hesitate to reach out to me.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

View solution in original post

2 REPLIES 2
Sahir_Maharaj
Super User
Super User

Hello @Solle,

 

Can you please try this:

 

  1. In Power Query, instead of directly calculating "TimeToMaturity" as a column, consider creating a calculated column that determines the "MaturityBucketID" based on the original "MaturityDate" and "As Of Date" columns.

  2. This calculated column should be assigned based on the criteria you specified (Under 2.25, Between 2.25 and 3.25, Above 3.25), using IF statements or custom functions.

  3. Create a measure that calculates the maximum "MaturityBucketID" for each ContractID based on the filtered time range from the slicer. When you're creating your matrix with "MaturityBucketName" and "ContractID" as rows, use the "MaxMaturityBucketID" measure as the values.

 

MaxMaturityBucketID = 
CALCULATE(
    MAX('YourTable'[MaturityBucketID]),
    ALLSELECTED('YourTable'),
    'YourTable'[As Of Date] >= MIN('DateSlicer'[StartDate]) &&
    'YourTable'[As Of Date] <= MAX('DateSlicer'[EndDate])
)

 

 

Should you require further details or information, please do not hesitate to reach out to me.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi @Sahir_Maharaj

Sorry for the late reply. 

I just tested your solution and it works smoothly, thank you for helping and taking your time to reply to my issue. 

Best Regards.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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