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
mcornejo_1
Helper I
Helper I

Previous Week Revenue and Counts

I am having a problem understanding the various ways of trying to sum (in my case) revenue and counts for the previous week from the current date. I think at this point I am overthinking things and have the various techniques confused so I am unable to explain what I’ve tried. It seems that DAX is the best way to approach this, however, I am completely new to it and confused.

 

Based on some random data I created I am trying to create a Report table that sums up Revenue for the previous week and groups it into the different Modes. We use ISO Week so Monday is day 1 of the week and Sunday is day 7. My sample report could be run at any time from date 6/4/18 to 6/8/18 but would contain all data from 5/28/18 through 6/3/18.

 

Any help would be greatly appreciated. I hope I’ve explained clear enough what I am trying to do.

 

Report:

Mode

Revenue

Count

Truckload

525

18

Expedite

400

10

LTL

420

12

Small Package

440

11

 

Underlying Data:

ID

Date

Revenue

Count

Mode

1002

5/28/2018

65

3

Truckload

1003

5/29/2018

70

2

Expedite

1004

5/29/2018

75

2

LTL

1005

5/30/2018

80

4

Small Package

1006

5/30/2018

85

5

Truckload

1007

5/30/2018

90

1

Expedite

1008

5/30/2018

95

3

LTL

1009

5/31/2018

100

2

Small Package

1010

5/31/2018

105

2

Truckload

1011

6/1/2018

110

4

Expedite

1012

6/1/2018

115

5

LTL

1013

6/1/2018

120

1

Small Package

1014

6/1/2018

125

3

Truckload

1015

6/2/2018

130

2

Expedite

1016

6/2/2018

135

2

LTL

1017

6/3/2018

140

4

Small Package

1018

6/3/2018

145

5

Truckload

2 REPLIES 2
v-yuta-msft
Community Support
Community Support

Hi mcornejo_1,

 

To achieve your requirement, you can create two measures using DAX like below:

Last Week Revenue =
VAR Previous_Week_Start_Date =
    MAX ( Table1[Date] ) - 8
VAR Previous_Week_Last_Date =
    MAX ( Table1[Date] ) - 1
RETURN
    CALCULATE (
        SUM ( Table1[Revenue] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Mode] ),
            Table1[Date] >= Previous_Week_Start_Date
                && Table1[Date] <= Previous_Week_Last_Date
        )
    )

Last Week Count =
VAR Previous_Week_Start_Date =
    MAX ( Table1[Date] ) - 8
VAR Previous_Week_Last_Date =
    MAX ( Table1[Date] ) - 1
RETURN
    CALCULATE (
        SUM ( Table1[Count] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Mode] ),
            Table1[Date] >= Previous_Week_Start_Date
                && Table1[Date] <= Previous_Week_Last_Date
        )
    )

捕获.PNG 

PBIX here for your reference: https://www.dropbox.com/s/v8adrqgefj3fxoh/Previous%20Week%20Revenue%20and%20Counts.pbix?dl=0.

 

Regards,

Jimmy Tao

Thank you for responding Jimmy. I should have added that the entire query includes 2 years of data but that this is just one small piece of the report. I attempted to create the Revenue measure first, however, it is returning a much larger amount of revenue for last week than it should.

 

When I try to look at detail it is returning data from last year through this year and showing duplicate revenue data for many shipments. I am not sure how it is summing up the Revenue because these numbers don't match the actual data at all. I included some actual data to show the unique values. Just to be clear the "Actual Revenue" column I manually added to the table below. Thank you.

 

ModeLast Week RevenueActual RevenueRevenueDateID
LTL103.13177.861/3/201770210686HB
LTL49240.07133.931/4/201770210760HB
LTL219516.63306.781/13/201770210767HB
LTL165201.81449.351/9/201770210773HB
LTL103.13226.071/3/201770210849HB
LTL103.13186.51/3/201770210910HB
LTL103.131651.731/3/201770210920HB
LTL165201.81706.021/9/201770210923HB
LTL92144.291128.891/5/201770210931HB
LTL49240.07187.931/4/201770210998HB
LTL132227.15403.531/6/201770211000HB
LTL49240.07384.051/4/201770211009HB
LTL203909.17236.41/10/201770211014HB
LTL49240.07153.251/4/201770211024HB
LTL218890.03441.561/12/201770211200HB
LTL49240.072311/4/201770211298HB
LTL103.13168.221/3/201770211387HB
LTL103.13266.461/3/201770211411HB
LTL92144.29246.871/5/201770211508HB
LTL49240.07650.681/4/201770211708HB
LTL49240.07553.751/4/201770211709HB
LTL49240.07204.771/4/201770211718HB
LTL49240.07327.31/4/201770211722HB
LTL49240.07285.51/4/201770211738HB
LTL103.13512.531/3/201770211750HB
LTL49240.07291.061/4/201770211752HB

 

 

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.