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
Anonymous
Not applicable

IF CURRENT WEEK SALE IS EMPTY

if current week sale is empty then need to calculate sales for the last non empty week sales. (for example if the current week is week number 5 and it doesnot have any sales data and week 2 does then i want it to show week 2 sales )
used following measure to calculate currweek sale:

 

payment currweek = CALCULATE(SUM('Table 3'[Payment]),FILTER(tbl_Calendar_ph,YEAR(tbl_Calendar_ph[Date])=YEAR(NOW())&&WEEKNUM(NOW())=tbl_Calendar_ph[Week Number]))

 

(PAYMENT IS SALES)
need something similar for previous week sales also
 THANKS for help.

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

You could use the last sale date instead of NOW().

 

Try this:

payment currweek =
VAR LastSaleDate =
    CALCULATE (
        MAX ( tbl_Calendar_ph[Date] ),
        FILTER ( tbl_Calendar_ph, CALCULATE ( SUM ( 'Table 3'[Payment] ) ) > 0 )
    )
RETURN
    CALCULATE (
        SUM ( 'Table 3'[Payment] ),
        FILTER (
            tbl_Calendar_ph,
            YEAR ( tbl_Calendar_ph[Date] ) = YEAR ( LastSaleDate )
                && WEEKNUM ( LastSaleDate ) = tbl_Calendar_ph[Week Number]
        )
    )

View solution in original post

4 REPLIES 4
AlexisOlson
Super User
Super User

You could use the last sale date instead of NOW().

 

Try this:

payment currweek =
VAR LastSaleDate =
    CALCULATE (
        MAX ( tbl_Calendar_ph[Date] ),
        FILTER ( tbl_Calendar_ph, CALCULATE ( SUM ( 'Table 3'[Payment] ) ) > 0 )
    )
RETURN
    CALCULATE (
        SUM ( 'Table 3'[Payment] ),
        FILTER (
            tbl_Calendar_ph,
            YEAR ( tbl_Calendar_ph[Date] ) = YEAR ( LastSaleDate )
                && WEEKNUM ( LastSaleDate ) = tbl_Calendar_ph[Week Number]
        )
    )
Anonymous
Not applicable

can i get same logic for previous week?

 

Try appending " - 7" to the LastSaleDate variable.

Anonymous
Not applicable

YOU ARE THE BEST

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.

Top Solution Authors