How to calculate number of weeks that the product is sold (per year), based on daily sales.
There is a daily sales table (millions of entries)
| BookingDate | ProductId | Pieces |
|---|---|---|
| 01-01-2023 | 1 | 10 |
| 01-02-2023 | 1 | 2 |
Product Table
| ProductId | ProductName | Price |
|---|---|---|
| 1 | Kiwi gold | 0.99 |
I'd like to know how many weeks each product has been active (sold at least once in a week) in a year
| Year | Product | WeeksActive |
|---|---|---|
| 2023 | Kiwi gold | 10 |
| 2023 | Kiwi green | 12 |
| 2022 | Kiwi gold | 50 |
This number is then needed to make further calculations. Is this possible?
(tried: extracted WeekNumber and Year from Booking date, tried creating a new table that holds articles per week per year, but don't know enough to build it)
I assume you want a DAX solution, but you tagged it for powerquery, so what the heck. Add columns to pull out the month and week. Remove all columns but the two columns and the ProductID. Remove all duplicate rows. Group on year and product ID
then merge in the name