Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Summarize by LAST date category

Hi! I have a table of Sales with Products, Categories and Dates of the sale, like this:

Product IDCategoryDate

A

X10-11-2019

A

Y30-11-2019

B

Y01-11-2019
BX07-11-2019

C

X10-11-2019
CY18-11-2019
CY28-11-2019

 
The thing is, I need to count how many products belong to a category, but the product can change its category in time, so we use this criterion: the Product belongs to the Category by which it was sold at the end of the given period (usually I visualize this month by month but could be by year too).

So for example, if I want to know how many products were X on November, I can make a DISTINCTCOUNT of the products by month filtered by category: that will give me a 3 (A,B, C) but it should be 1 (just B), and if I count the Y products on November I would also get a 3, but it should be a 2.

Why do we need this LAST category standard? because this DISTINCTCOUNT gives me a total of 3 Products on X and 3 on Y, which is a contradiction, because I don't have 6 products, I only have A, B and C.
It also mess up things when I need to make more advanced calculations, like for example "How many products were sold just once on november?" if I make the Measure and then filter by category, taking the Y out, A B and C would appear, which is false because the three of them were sold more than once.

This has been a really tricky problem and I don't know how to solve it, I've tried by myself and with the help of two consultants, no one could give me a solution neither with Calculated Columns nor with Measures. I know there must be at least one person with the same problem that already solved it or some Power BI expert in this great Community, come out wherever you are please! I would very much appreciate your help,

Best regards,
Gabriela Sofía

3 Replies