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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
agarwala
Helper I
Helper I

Deleted

Deleted

1 ACCEPTED SOLUTION
shafiz_p
Super User
Super User

Hi @agarwala  If I understood correctly, to provide the flexibility of choosing dates along with the existing logic, you can use a combination of slicers and measures in Power BI.

First create a date slicer with between slicer settings. Then create two measure for start and end date:

SelectedStartDate = 
MIN('DateTable'[Date])

SelectedEndDate = 
MAX('DateTable'[Date])

Here is the image:

shafiz_p_0-1730262380421.png

Modify your measure to use selected date if select else default calculation:

Waste Quantity (t) =
VAR SelectedMonths = SELECTEDVALUE('Last Months Selection'[Number Of Months (Excludes Current Month)], 18) --- Default to 18

VAR CurrentDate = TODAY()
VAR StartDate = EDATE(CurrentDate, -SelectedMonths)
VAR EndDate = EOMONTH(CurrentDate, -1)

VAR DynamicStartDate = IF(ISBLANK([SelectedStartDate]), StartDate, [SelectedStartDate])
VAR DynamicEndDate = IF(ISBLANK([SelectedEndDate]), EndDate, [SelectedEndDate])

RETURN
CALCULATE(
    SUM(WASTE_API_DATA[Original Waste Quantity (t)]),
    WASTE_API_DATA[ACTIVITY_DATE] >= DynamicStartDate &&
    WASTE_API_DATA[ACTIVITY_DATE] <= DynamicEndDate
)

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and kudos!!

 

Best Regards,
Shahariar Hafiz

View solution in original post

4 REPLIES 4
agarwala
Helper I
Helper I

Thank you so much for all the suggestions.

They really helped me.

Arti

shafiz_p
Super User
Super User

Hi @agarwala  If I understood correctly, to provide the flexibility of choosing dates along with the existing logic, you can use a combination of slicers and measures in Power BI.

First create a date slicer with between slicer settings. Then create two measure for start and end date:

SelectedStartDate = 
MIN('DateTable'[Date])

SelectedEndDate = 
MAX('DateTable'[Date])

Here is the image:

shafiz_p_0-1730262380421.png

Modify your measure to use selected date if select else default calculation:

Waste Quantity (t) =
VAR SelectedMonths = SELECTEDVALUE('Last Months Selection'[Number Of Months (Excludes Current Month)], 18) --- Default to 18

VAR CurrentDate = TODAY()
VAR StartDate = EDATE(CurrentDate, -SelectedMonths)
VAR EndDate = EOMONTH(CurrentDate, -1)

VAR DynamicStartDate = IF(ISBLANK([SelectedStartDate]), StartDate, [SelectedStartDate])
VAR DynamicEndDate = IF(ISBLANK([SelectedEndDate]), EndDate, [SelectedEndDate])

RETURN
CALCULATE(
    SUM(WASTE_API_DATA[Original Waste Quantity (t)]),
    WASTE_API_DATA[ACTIVITY_DATE] >= DynamicStartDate &&
    WASTE_API_DATA[ACTIVITY_DATE] <= DynamicEndDate
)

 

 

Hope this helps!!

If this solved your problem, please accept it as a solution and kudos!!

 

Best Regards,
Shahariar Hafiz

johncolley
Solution Sage
Solution Sage

Hi @agarwala ,


Include in your date table the following variable:

  var _today = TODAY()

 

As well as the following column:

 

"Month Offset", DATEDIFF(_today, [Date column], MONTH)

 

You can then use this Month Offset column in a filter or slicer to allow the user to select whatever range of months they require. Your current default would equate to -1 to -18, with 0 being the current month.

 

Hope this helps.

Ritaf1983
Super User
Super User

Hi @agarwala 

It’s a bit unclear exactly what you’re trying to accomplish. Here’s a link on working with dynamic date periods in Power BI, which might help you set up the flexibility you need for selecting dates at runtime.

https://www.youtube.com/watch?v=Xi86HHEaY_M

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

If this doesn’t match your needs, could you please provide an example of what you’re trying to achieve? This will help us guide you more effectively.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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