cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerbidevelope Frequent Visitor
Frequent Visitor

Weekly Sales - Last week not null sales

Hi Everyone,

 

we have a date dimension and sales fact table. we have to display sales by week.

 

dropdown slicer: week(feb 4 - feb 10).

 

when we display sales, if the selected week does not have sales, we should consider the previous week, till the week which is having the sales.

 

How do we do that using DAX?

1 ACCEPTED SOLUTION

Accepted Solutions
v-cherch-msft Super Contributor
Super Contributor

Re: Weekly Sales - Last week not null sales

Hi @powerbidevelope 

 

Kindly mark the answer as a solution to close this thread.

 

Regards,

Cherie

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

View solution in original post

8 REPLIES 8
LivioLanzo Super Contributor
Super Contributor

Re: Weekly Sales - Last week not null sales

Hi @powerbidevelope 

 

are you able to post a dastaset sample?

 

thanks

 

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

powerbidevelope Frequent Visitor
Frequent Visitor

Re: Weekly Sales - Last week not null sales

@LivioLanzo 

 

How do i attach sample pbix or dataset here?

 

Thanks..

v-cherch-msft Super Contributor
Super Contributor

Re: Weekly Sales - Last week not null sales

Hi @powerbidevelope 

 

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
powerbidevelope Frequent Visitor
Frequent Visitor

Re: Weekly Sales - Last week not null sales

Hi @LivioLanzo  and @v-cherch-msft 

 

plz find the sample dataset and pbix files.

 

https://github.com/bodempudi/CodeSnippets/blob/master/PowerBI/Demos/DataSet.xlsx

 

https://github.com/bodempudi/CodeSnippets/blob/master/PowerBI/Demos/sample_pbix_file.pbix

 

i have the PBIX file too, please select the week date range and see the stacked chart. when we have sales for a particular week, we should consider the previous week, which is having sales.

 

Thanks..

v-cherch-msft Super Contributor
Super Contributor

Re: Weekly Sales - Last week not null sales

Hi @powerbidevelope 

 

You may try below measure.Attached the file for your reference.

Measure = 
VAR LastWeek_notnullsales =
    IF (
        [SUM_Sales] = BLANK (),
        MAXX (
            FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] < MAX ( Dimdate[WeekOfYear] ) ),
            [WeekIndex]
        ),
        MAX ( Dimdate[WeekOfYear] )
    )
RETURN
    CALCULATE (
        [SUM_Sales],
        FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] = LastWeek_notnullsales )
    )

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
powerbidevelope Frequent Visitor
Frequent Visitor

Re: Weekly Sales - Last week not null sales

Hi @v-cherch-msft 

 

it is not working when user selects multiple weeks.

 

in our example, if users selects Feb 17-Feb 23 and Feb 24 - Feb 28. it should display Feb 17- Feb 23.

 

It is not working, it is displaying blank report.

 

Thanks..

powerbidevelope Frequent Visitor
Frequent Visitor

Re: Weekly Sales - Last week not null sales

after modifying the expression as below it is working fine..

 


Measure =
var week=max(Dimdate[WeekOfYear])
VAR LastWeek_notnullsales =
IF (
(CALCULATE([SUM_Sales],Dimdate[WeekOfYear]=week) = BLANK ()),
MAXX (
FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] < MAX ( Dimdate[WeekOfYear] ) ),
[WeekIndex]
),
MAX ( Dimdate[WeekOfYear] )
)
RETURN
CALCULATE (
[SUM_Sales],
FILTER ( ALL ( Dimdate ), Dimdate[WeekOfYear] = LastWeek_notnullsales )
)

v-cherch-msft Super Contributor
Super Contributor

Re: Weekly Sales - Last week not null sales

Hi @powerbidevelope 

 

Kindly mark the answer as a solution to close this thread.

 

Regards,

Cherie

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

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 47 members 877 guests
Please welcome our newest community members: