Forum Discussion
Deleted
- 1 year ago
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:
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
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:
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