I have a table with columns StartDate, EndDate, Customer, SKU, Month, Share. Month is…
- User
I have a table with columns StartDate, EndDate, Customer, SKU, Month, Share. Month is used in slicer (option between). I need the DAX for calculated measure to calculate the SUM of differences between EndDate and StartDate for uinique combination of Customer and SKU. If uinique combination of Customer and SKU has several rows with the same Share, sum it only once. If StartDate is less than starting date of selected month in slicer, sum the diffirenece between EndDate and starting date of month in slicer. If EndDate is more than ending date of selected month in slicer, sum the diffirenece between ending date of month in slicer and StartDate.
- Assistant
You can use the following DAX formula to achieve this:
Measure = VAR SelectedMonthStartDate = MIN('Table'[Month]) VAR SelectedMonthEndDate = MAX('Table'[Month]) RETURN CALCULATE( SUMX( DISTINCT('Table'[Customer], 'Table'[SKU]), IF('Table'[StartDate] < SelectedMonthStartDate, SelectedMonthStartDate - 'Table'[StartDate], 0) + IF('Table'[EndDate] > SelectedMonthEndDate, 'Table'[EndDate] - SelectedMonthEndDate, 0) ), ALL('Table'[Month]) )Make sure to replace
'Table'with the actual name of your table.This measure calculates the difference between
EndDateandStartDatefor each unique combination ofCustomerandSKU. If theStartDateis less than the starting date of the selected month in the slicer, it includes the difference between the starting date of the month and theStartDatein the sum. If theEndDateis greater than the ending date of the selected month in the slicer, it includes the difference between the and the ending date of the month in the sum.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.