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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Sum for last 7 working days

I need to calculate the change in qty between last 7 days and previous 7 days.  I am doing that by:

Qty Change 7d = calculate([Returned Qty],DATESBETWEEN('DateTable'[Date],TODAY()-8,TODAY()) - calculate([Returned Qty],DATESBETWEEN('DateTable'[Date],TODAY()-7,TODAY()-15))

 

I am using a Date Dim table and I do have week names and week numbers in the table. How do I change the DAX to only include last 7 working days (and 7 working days prior to that) & exclude Saturday and Sunday? 

 

Many Thanks. 

 

 

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @Anonymous,

 

Based on my test, you should be able to follow steps below to get your expected. Smiley Happy

 

1. Use the formula below to add a calculate column in your DateTable that is 1 for workdays and 0 for non-workdays.

IsWorkday = SWITCH(WEEKDAY('DateTable'[Date]),1,0,7,0,1)

2. User the formula below to create a measure to calculate the workdays between a date and Today.

Count Of Workday =
COUNTROWS (
    FILTER (
        ALL ( 'DateTable' ),
        'DateTable'[Date] <= TODAY ()
            && 'DateTable'[Date] >= MAX ( 'DateTable'[Date] )
            && 'DateTable'[IsWorkday] = 1
    )
)

3. Then you should be able to use the formula below to create the measure to calculate the change in qty between last 7 days and previous 7 days.

Qty Change 7d =
CALCULATE (
    [Returned Qty],
    FILTER ( 'DateTable', [Count Of Workday] > 0 && [Count Of Workday] <= 8 )
)
    - CALCULATE (
        [Returned Qty],
        FILTER ( 'DateTable', [Count Of Workday] > 8 && [Count Of Workday] <= 15 )
    )

 

Regards

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi all, I've created a table showing the balance and two measures to show the rpevious days balance and the difference between the two balances.

 

I'm trying to create a measure which works out the net difference for the last 7 days. Could someone please help?

 

gh614_0-1652970251032.png

 

v-ljerr-msft
Employee
Employee

Hi @Anonymous,

 

Based on my test, you should be able to follow steps below to get your expected. Smiley Happy

 

1. Use the formula below to add a calculate column in your DateTable that is 1 for workdays and 0 for non-workdays.

IsWorkday = SWITCH(WEEKDAY('DateTable'[Date]),1,0,7,0,1)

2. User the formula below to create a measure to calculate the workdays between a date and Today.

Count Of Workday =
COUNTROWS (
    FILTER (
        ALL ( 'DateTable' ),
        'DateTable'[Date] <= TODAY ()
            && 'DateTable'[Date] >= MAX ( 'DateTable'[Date] )
            && 'DateTable'[IsWorkday] = 1
    )
)

3. Then you should be able to use the formula below to create the measure to calculate the change in qty between last 7 days and previous 7 days.

Qty Change 7d =
CALCULATE (
    [Returned Qty],
    FILTER ( 'DateTable', [Count Of Workday] > 0 && [Count Of Workday] <= 8 )
)
    - CALCULATE (
        [Returned Qty],
        FILTER ( 'DateTable', [Count Of Workday] > 8 && [Count Of Workday] <= 15 )
    )

 

Regards

Anonymous
Not applicable

Awesome.. Thanks.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.