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
alexrf86
Helper III
Helper III

calculate sales between 2 periodos

Hi community!

 

I am trying to reach the last week sales amount and split them between Monday to Sunday.

 

I tried 2 different ways but I have also got the same problem, I was able to get only the total week sales:

 

day_week_name_

sales-1w

Monday

8390

Tuesday

8390

Wednesday

8390

Thursday

8390

Friday

8390

Saturday

8390

Sunday

8390

 

My first tried was to create a DATESINPERIOD measure:

 

sales-1w = CALCULATE([orders_number]; DATESINPERIOD(Calendario_pedido[Order_day];TODAY()-1;-7;DAY))

 

As I got the above issue, I have also attempted to create 2 new columns:

 

Last_Monday = Calendario_pedido[Order_day] - WEEKDAY(Calendario_pedido[Order_day];2) -6

 

Last_Sunday = LASTDATE ( Calendario_pedido[Order_day] ) - WEEKDAY ( LASTDATE (Calendario_pedido[Order_day]); 2 )

 

And with the measure formula:

 

sales-1w = CALCULATE([sales];

DATESBETWEEN (Calendario_pedido[Order_day];

MIN(Calendario_pedido[Last_Monday]);

MAX(Calendario_pedido[Last_Sunday ])))

 

 

As you may see, any of these 2 ways let me split the total sales amount (€8390) within Monday to Sunday.

 

May anyone help me please?

 

Thanks

1 ACCEPTED SOLUTION

I got the solution myself.

 

First of all I created a new column in the calendar: 

 

week_order = WEEKNUM(TODAY())-Calendario_pedido[Week_num_order]
 
Basically it gives me the week number based on the current week.
 
Then I have just needed to create the measures:
 
current_week_sales= CALCULATE([sales]; Calendario_pedido[week_order] = 0)
 
last_week_sales= CALCULATE([sales]; Calendario_pedido[week_order] = 1)
 
etc etc

View solution in original post

7 REPLIES 7
Icey
Community Support
Community Support

Hi @alexrf86 ,

 

Please share me a dummy PBIX file, in which the sample data has the same data structure as your real data. Please remove sensitive information. And then, I will conduct specific tests.

 

 

Best Regards,

Icey

Hi.

 

You can download a dummy file here:

 

https://drive.google.com/open?id=1HSNCfpCy-YGdZ_9zoQs9A6cm2npmOeSP

 

You will find the 3 ways I tried to sort out this issue, each one in a different table. However none works properly.

 

https://drive.google.com/open?id=1HSNCfpCy-YGdZ_9zoQs9A6cm2npmOeSP

 

Thanks

amitchandak
Super User
Super User

As Suggested by @Greg_Deckler , use weeknum with option 2, that will give you week Monday to Sunday

weeknum(date[date],2)

Refer to this file: https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0

Using Rank to get last week.

Greg_Deckler
Super User
Super User

Have you looked at WEEKNUM?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Weeknum as filter does not let me to choose the last 3 weeks, so every week I should edit the filter.

 

Week Rank does not split weeks properly as it takes a week as the last 7 days instead of natural weeks.

I got the solution myself.

 

First of all I created a new column in the calendar: 

 

week_order = WEEKNUM(TODAY())-Calendario_pedido[Week_num_order]
 
Basically it gives me the week number based on the current week.
 
Then I have just needed to create the measures:
 
current_week_sales= CALCULATE([sales]; Calendario_pedido[week_order] = 0)
 
last_week_sales= CALCULATE([sales]; Calendario_pedido[week_order] = 1)
 
etc etc

I need 4 weekly columns splitting the sales within Monday to Sunday: current week, last week, 2 weeks ago and 3 weeks ago.

 

It should be something like this:

 

weekdayCurrent WeekLast Week2 weeks ago
Monday122422
Tuesday255531
Wednesday334344
Thursday 5532
Friday 5433
Saturday 2241
Sunday 1223

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.