Forum Discussion
Same Week last Year Flag
First, thanks so much for your response!
I attempted to implement this solution, but received "N" for every single result, so it doesn't appear to be working. I'd love to include a more thorough file that includes an anonymized version of the data I'm working with, but I don't see a way to attach files here. Is there some way I can send it to you?
Thanks!
Hi Anonymous ,
Please read this post.
Best Regards,
Community Support Team_Gao
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
- Anonymous4 years agoNot applicable
I've attached two columns of anonymized data from the project I'm working on. There are several repeats in dates/brands, but this is because there is an additional column in my actual file that includes all of the different partners/stores we deal with.
Let me know if I can provide anything else and thanks again!
Link: https://drive.google.com/file/d/1YmP5ETQ4uMcwVMCTHKzV-F3Nsc1qazpZ/view?usp=sharing
- Anonymous4 years agoNot applicable
Hi Anonymous ,
I modified the expression, please help me to check if they work correctly.
week_and_year = YEAR('Sheet1'[DT])+WEEKNUM('Sheet1'[DT],21)*10000Column = var _value_1 = 'Sheet1'[BRAND_VALUE] var _value_2 = 'Sheet1'[week_and_year] var _value_3 = 'Sheet1'[week_and_year] - 1 var _value_4 = 'Sheet1'[week_and_year] + 1 var _value_5 = CALCULATE(COUNT('Sheet1'[BRAND_VALUE]),FILTER('Sheet1','Sheet1'[BRAND_VALUE]=_value_1),FILTER('Sheet1',Sheet1[week_and_year]=_value_2)) var _value_6 = CALCULATE(COUNT('Sheet1'[BRAND_VALUE]),FILTER('Sheet1','Sheet1'[BRAND_VALUE]=_value_1),FILTER('Sheet1',Sheet1[week_and_year]=_value_3)) var _value_7 = CALCULATE(COUNT('Sheet1'[BRAND_VALUE]),FILTER('Sheet1','Sheet1'[BRAND_VALUE]=_value_1),FILTER('Sheet1',Sheet1[week_and_year]=_value_4)) RETURN SWITCH( TRUE(), (_value_5 <> BLANK() && _value_6 <> BLANK()) || (_value_5 <> BLANK() && _value_7 <> BLANK()),"Y", "N" )But the table has a lot of duplicate data, the same data only needs to output one result, it is recommended to use the following method, which will save a lot of memory.
First, we need a calendar table with three fields for date, year, and week. And create a relationship between sheet1 tables
Then create a new calculated table.
Table = SUMMARIZE('Sheet1','Sheet1'[BRAND_VALUE],'Date'[Year],'Date'[Week])Please create a calculated column next.
Column = VAR _brand_value = 'Table'[BRAND_VALUE] VAR _year = 'Table'[Year] VAR _year_1 = 'Table'[Year] - 1 VAR _year_2 = 'Table'[Year] + 1 VAR _week = 'Table'[Week] VAR _value_1 = CALCULATE ( COUNT ( 'Table'[BRAND_VALUE] ), FILTER ( 'Table', 'Table'[BRAND_VALUE] = _brand_value && 'Table'[Year] = _year && 'Table'[Week] = _week ) ) VAR _value_2 = CALCULATE ( COUNT ( 'Table'[BRAND_VALUE] ), FILTER ( 'Table', 'Table'[BRAND_VALUE] = _brand_value && 'Table'[Year] = _year_1 && 'Table'[Week] = _week ) ) VAR _value_3 = CALCULATE ( COUNT ( 'Table'[BRAND_VALUE] ), FILTER ( 'Table', 'Table'[BRAND_VALUE] = _brand_value && 'Table'[Year] = _year_2 && 'Table'[Week] = _week ) ) RETURN SWITCH ( TRUE (), (_value_1 <> BLANK()&& _value_2 <> BLANK()) || (_value_1 <> BLANK()&& _value_3 <> BLANK()), "Y", "N" )Attach the PBIX file for reference. Hope it helps.
Best Regards,
Community Support Team_GaoIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
How to get your questions answered quickly -- How to provide sample data
- Anonymous4 years agoNot applicable
I've tested this solution both in my original dataset and the test dataset I've provided. In both, I found some brands missing where they should be included(or brands included where they should be missing). I'll list an example picture below.
Also, as I said before the duplicates exist because in the table I'm using, there is an additional "Retailer" column which lists out the different retailers these brands are sold in.
In this example below, it mentions 'Y' in the 62021 column for brand 5 existing last year, but brand 5 was not sold in 62020. I'm wondering if possibly weeks are being skewed slightly by years that count 53 weeks instead of 52? Once again, thank you so much for your assistance in this solution!