I have a table with columns Client, Product, Date, StartDate, EndDate, PromoVol,…
- User
I have a table with columns Client, Product, Date, StartDate, EndDate, PromoVol, TotalVol where StartDate and EndDate are starting and ending dates of promo period, PromoVol is promo volume and TotalVol is total volume that includes both promo volume and regular volume. Each product for each client can be sold several times. It means that there are many promo periods for each product and client. If we have a range of dates from january 2023 to june 2023 Product 1 for Client 1 can have three promo periods, while Product 2 for Client 2 can have four promo periods. Tell how to use DAX to determine all periods between promo perdios for unique combination of Client and Product during the considered period of time (all range in column Date). How to determine volumes sold during promo periods and outside promo periods. How to visualize that?
- Assistant
To determine all periods between promo periods for a unique combination of Client and Product during the specified period of time, you can use the following DAX measures:
- First, create a calculated column to identify whether a date is within a promo period for each Client and Product combination:
In Promo Period = IF( AND( 'Table'[Date] >= 'Table'[StartDate], 'Table'[Date] <= 'Table'[EndDate] ), 1, 0 )- Next, create a calculated table to generate all the periods between promo periods for each Client and Product combination:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), CALENDAR(MinDate, MaxDate) ) - User
Your measures does not take into account the fact that each combination of Product and SKU can have several promo times
- Assistant
Apologies for the oversight. If each combination of Product and Client can have multiple promo periods, you can modify the measures as follows:
- Create a calculated column to identify whether a date is within any promo period for each Client and Product combination:
In Promo Period = CALCULATE( MAXX( FILTER( 'Table', 'Table'[Client] = EARLIER('Table'[Client]) && 'Table'[Product] = EARLIER('Table'[Product]) && 'Table'[Date] >= 'Table'[StartDate] && 'Table'[Date] <= 'Table'[EndDate] ), 1 ) )- Create a calculated table to generate all the periods between promo periods for each Client and Product combination:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), CALCULATETABLE( CALENDAR(MinDate, MaxDate), ALL('Table'), 'Table'[In Promo Period] = 0 ) ) - User
Modify the DAX taking into account that rows have empty StartDate and EndDate if they do not refer to promo sell
- Assistant
To modify the DAX measures to account for rows with empty StartDate and EndDate if they do not refer to a promo sell, you can use the following updated measures:
- Create a calculated column to identify whether a date is within any promo period for each Client and Product combination:
In Promo Period = IF( AND( 'Table'[Date] >= 'Table'[StartDate], 'Table'[Date] <= 'Table'[EndDate], NOT(ISBLANK('Table'[StartDate])), NOT(ISBLANK('Table'[EndDate])) ), 1, 0 )- Create a calculated table to generate all the periods between promo periods for each Client and Product combination:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), CALCULATETABLE( CALENDAR(MinDate, MaxDate), ALL('Table'), 'Table'[In Promo Period] = 0 ) ) - User
Periods Between Promos also shows dates when there is a promo period
- Assistant
Apologies for the confusion. In order to exclude the dates when there is a promo period from the "Periods Between Promos" calculation, you can modify the DAX measure as follows:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE( GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), CALENDAR(MinDate, MaxDate) ), NOT('Table'[In Promo Period] = 1) )By applying the
NOT('Table'[In Promo Period] = 1)filter condition, only the dates outside of promo periods will be included in the "Periods Between Promos" table calculation.Apologies for any inconvenience caused. Please let me know if you have any further questions!
- User
Now, the Periods Between Promos yields empty table. Moreover from Periods Between Promos should be excluded all periods from StartDate and EndDate for each combination of Clients and Products
- Assistant
Apologies for the confusion once again. To correctly exclude the promo periods from the "Periods Between Promos" calculation and generate the periods between promo periods for each combination of Clients and Products, you can modify the DAX measure as follows:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE( GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), FILTER( CALENDAR(MinDate, MaxDate), NOT( CALCULATE( COUNTROWS('Table'), 'Table'[Client] = EARLIER('Table'[Client]) && 'Table'[Product] = EARLIER('Table'[Product]) && 'Table'[Date] >= EARLIER('Table'[StartDate]) && 'Table'[Date] <= EARLIER('Table'[EndDate]) ) > 0 ) ) ), ALL('Table') )The modified measure correctly filters out the periods between promo periods considering each combination of Clients and Products. It excludes the periods within promo periods for each combination by checking if there are any rows where the date falls between the StartDate and EndDate.
- User
The error is A single value for column 'start_date' in table 'Share16вед' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
- Assistant
Apologies for the error. To resolve the issue and correctly calculate the periods between promo periods while excluding the promo period dates for each combination of Clients and Products, you can modify the DAX measure as follows:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE( GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), VAR PromoPeriods = FILTER( 'Table', 'Table'[Client] = EARLIER('Table'[Client]) && 'Table'[Product] = EARLIER('Table'[Product]) && NOT(ISBLANK('Table'[StartDate])) && NOT(ISBLANK('Table'[EndDate])) ) RETURN EXCEPT( CALENDAR(MinDate, MaxDate), SELECTCOLUMNS(PromoPeriods, "Date", 'Table'[Date]) ) ), ALL('Table') )In the updated measure, we use a variable
PromoPeriodsto filter the 'Table' based on the combination of Client and Product while excluding rows with empty StartDate and EndDate. Then, we use to exclude the Date values from PromoPeriods and generate the periods between promo periods for each combination. - User
The funtcion is better but the result is still not almost accurate. If promo period has dates from 06.06.2023 to 06.16.2023 then all dates from 06.06.2023 to 06.16.2023 should be removed from Periods Between Promos. Now, only removed dates 06.06.2023, 06.10.2023, and 06.12.2023 when sells are made. Note that not each day there are sells during promo period
- Assistant
Apologies for the misunderstanding. To correctly exclude all dates within the promo period from "Periods Between Promos", regardless of whether sales were made on those dates, you can modify the DAX measure as follows:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE( GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), VAR PromoPeriods = FILTER( VALUES('Table'[Date]), 'Table'[Client] = EARLIER('Table'[Client]) && 'Table'[Product] = EARLIER('Table'[Product]) && 'Table'[In Promo Period] = 1 ) VAR PromoDates = SUMMARIZE( PromoPeriods, 'Table'[Date], "SalesCount", COUNTROWS(PromoPeriods) ) VAR AllDates = CALENDAR(MinDate, MaxDate) RETURN EXCEPT( AllDates, SELECTCOLUMNS(PromoDates, "Date", 'Table'[Date]) ) ), ALL('Table') ) - User
There is an error A single value for column '__In Promo Period' in table 'Share16вед' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.
- Assistant
I apologize for the error. Let's modify the DAX measure again to resolve this issue:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE( GENERATE( SUMMARIZE('Table', 'Table'[Client], 'Table'[Product]), VAR PromoPeriods = FILTER( 'Table', 'Table'[Client] = EARLIER('Table'[Client]) && 'Table'[Product] = EARLIER('Table'[Product]) && NOT(ISBLANK('Table'[StartDate])) && NOT(ISBLANK('Table'[EndDate])) ) VAR PromoDates = SUMMARIZE( PromoPeriods, 'Table'[Date], "SalesCount", COUNTROWS('Table') ) VAR AllDates = CALENDAR(MinDate, MaxDate) RETURN EXCEPT( AllDates, SELECTCOLUMNS(PromoDates, "Date", 'Table'[Date]) ) ), ALL('Table') )In this modified measure, we use to count the rows in the PromoPeriods table, regardless of column '__In Promo Period'. This helps avoid the error message you encountered, as we no longer rely on the '__In Promo Period' column in the filter condition.
- User
This DAX does not exlcude all dates within the promo period from “Periods Between Promos”, regardless of whether sales were made on those dates
- Assistant
Apologies for the oversight. To correctly exclude all dates within the promo period from “Periods Between Promos”, regardless of whether sales were made on those dates, you can modify the DAX measure as follows:
Periods Between Promos = VAR MinDate = MIN('Table'[Date]) VAR MaxDate = MAX('Table'[Date]) RETURN CALCULATETABLE ( GENERATE ( SUMMARIZE ( 'Table', 'Table'[Client], 'Table'[Product] ), VAR PromoPeriods = FILTER ( VALUES ( 'Table'[Date] ), 'Table'[Client] = EARLIER ( 'Table'[Client] ) && 'Table'[Product] = EARLIER ( 'Table'[Product] ) ) VAR PromoDates = SELECTCOLUMNS ( PromoPeriods, "Date", 'Table'[Date] ) VAR AllDates = CALENDAR ( MinDate, MaxDate ) RETURN EXCEPT ( AllDates, PromoDates ) ), ALL ( 'Table'[In Promo Period] ) )In this modification, we are filtering
PromoPeriodsusing to get all unique dates within the promo period for each combination of Client and Product. Then, we select only the "Date" column from using to create . Finally, we exclude from using to generate the periods between promo periods.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.