Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
calimero48
Helper II
Helper II

Same week previous year

Hi

 

I have create a measure to get the sum of sale from previous year same week as

 

        IF ( HASONEVALUE (DAT[CalendarYear]), CALCULATE (SUM ([CA]),    
                    FILTER (ALL ( DAT),
                            DAT[CalendarYear] = VALUES ( DAT[CalendarYear] ) - 1     && CONTAINS(
                            VALUES ( DAT[WeekNumberOfYear] ),
                            DAT[WeekNumberOfYear],
                            DAT[WeekNumberOfYear] ))),BLANK())

 

This measure works well until we drill down. For exemple, if I want to split to sales to product and in one week of the current year we do not have any sales, the measure do not return any previous sales.

 

What I am doing wrong? Thanks in advance for your helps

 

Regards

 

 

7 REPLIES 7
v-chuncz-msft
Community Support
Community Support

@calimero48,

 

Check if the following link helps.

https://www.sqlbi.com/articles/compare-equivalent-periods-in-dax/

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi

 

Thank you for your reply. I start with this article.

 

Let me explain :

 

Fact table is

Date|Vendor|Manager|Article|Value

2017-01-04|v01|M01|A01|10

2017-01-11|v02|M01|A01|20

2017-01-05|v02|M01|A01|10

2018-01-24|v01|M01|A01|10

2018-01-12|v02|M01|A01|10

 

 

With my  measure if i do

week / Manager/vendor  Previous year same week /Current year week

 

I got

W1                  2017         2018

    A01              20             10

            V01                            ( I do not have sales in 2018 week 1)

            V01                       10

W2

    A01               20           10

            V02       20           10 ( I  have sales in 2018 week 2)

 

 

What i understand is that my measure for the previous week year is taking only week of the current year having sales.

 

How to avoid this?

 

Thanks for your help

Hi

 

I have read Marco Russo article

https://www.sqlbi.com/articles/week-based-time-intelligence-in-dax/

 

What I found, it's when I do not have any value on the current year/week, the measure is not calculated for the previous year.

 

How to have it working ?

 

Regards

 

Hi

 

To go further in the debug,  I found that if there is not data for the current year, VALUES ( DAT[WeekNumberOfYear]) return blank.

 

How can I have the selected weekNumber returned even if there is no data for the current year.

 

Thanks in advance for your help

 

 

Here's a thought.

 

If you divide the sales figue by itself you will come up with one of two values: 1 or 0 (because anything divided by itself will be 1 and anything divided by zero will be zero). Then multiple the resulting value by your full measure. The result will be either 1 * [MEASURE] or 0 * [MEASURE].

 

This might return the sales in the current week having no sales as zero as you seem to require. (Sorry I haven't tested this.)

Hi

 

 

Thanks for your suggestion but my problem is that the measure of the previous year same week does not give the correct result.

the measure "previous year same week" does not include all fact table of the previous year week if, there is no sales in the current year.

 

Regards

calimero48
Helper II
Helper II

Sorry,

 

I forgot the give the DAT table structure

CalendarYear Integer  -> Year

WeekNumberOfYear  -> Integer -> Week number (1 to 53)

FullAlternateDate -> Date

MonthNumber Integer -> Month

 

at least

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.