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
MarceloPereira
Frequent Visitor

Exclude weekend using dateadd

Hi Everyone.

 

I need help to compare the margin of sales.

 

When I compare Monday's sales margin with the day before, the DATEADD function searches for Sunday's margin, where I don't have sales. I need to compare Monday's margin to Friday's margin, excluding the weekend in my calculation.

 

powerbiHelp.PNG

 

In my case, number 6 is Saturday and 0 is sunday.

 

There is any way to do it?

 

Best regards

1 ACCEPTED SOLUTION

Hi @MarceloPereira ,
Try this instead:

C_MargemTeste = 
var _Date = MAX(DIM_CALENDARIO[Date])
var _isWeekday = WEEKDAY(_Date, 2)
RETURN
SWITCH(TRUE(),
_isWeekday = 1, CALCULATE([C_Margem], DIM_CALENDARIO[Data] = _Date - 3),
_isWeekday > 1 && _isWeekday <= 5, CALCULATE([C_Margem],  DIM_CALENDARIO[Data] = _Date - 1))

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

10 REPLIES 10

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.