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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
KCroninKrein
Regular Visitor

Calculate Last Week's Value for a Particular Line of Business

Hi everyone! 

 

I have weekly revenue data for 3 lines of business, and I am trying to calculate for each line of business what the change in revenue is week-to-week. I suspect that I could do this by splitting the data into 3 tables (one per Line of Business), but I would rather keep the data together in one table to simplify the model. 

 

Below is my sample (dummy) data:

WeekLine_Of_BusinessOpportunity_Revenue
8/12/2019A123
8/12/2019B456
8/12/2019C789
8/19/2019A120
8/19/2019B446
8/19/2019C782
8/26/2019A131
8/26/2019B445
8/26/2019C788
9/2/2019A125
9/2/2019B455
9/2/2019C800
9/9/2019A134
9/9/2019B446
9/9/2019C800
9/16/2019A137
9/16/2019B446
9/16/2019C803

 

Right now, I am using the following DAX to calculate the Previous_Week_Revenue for each Line of Business:

 

 

 

Previous_Week_Revenue =
VAR Pre_date =
    CALCULATE (
        MAX ( 'Sales Pipeline'[Week] ),
        'Sales Pipeline',
        'Sales Pipeline'[Week] < EARLIER ( 'Sales Pipeline'[Week] )
    )
RETURN
    CALCULATE (
        SUM ( 'Sales Pipeline'[Opportunity Revenue] ),
        'Sales Pipeline',
        'Sales Pipeline'[Week] = Pre_date
    )

 

 

 

 

However, this code is giving me the total revenue per week, rather than for the particular line of business. 

Current Result: 

WeekLine_Of_BusinessOpportunity_RevenuePrevious_Week_Revenue
8/12/2019A123 
8/12/2019B456 
8/12/2019C789 
8/19/2019A1201368
8/19/2019B4461368
8/19/2019C7821368
8/26/2019A1311348
8/26/2019B4451348
8/26/2019C7881348
9/2/2019A1251364
9/2/2019B4551364
9/2/2019C8001364
9/9/2019A1341380
9/9/2019B4461380
9/9/2019C8001380
9/16/2019A1371380
9/16/2019B4461380
9/16/2019C8031380

 

And my desired output looks like this: 

WeekLine_Of_BusinessOpportunity_RevenuePrevious_Week_Revenue
8/12/2019A123 
8/12/2019B456 
8/12/2019C789 
8/19/2019A120123
8/19/2019B446456
8/19/2019C782789
8/26/2019A131120
8/26/2019B445446
8/26/2019C788782
9/2/2019A125131
9/2/2019B455445
9/2/2019C800788
9/9/2019A134125
9/9/2019B446455
9/9/2019C800800
9/16/2019A137134
9/16/2019B446446
9/16/2019C803800

 

It seems like there should be a way to tell the model to look at the previous week value and filter on the row that matches the Line of Business value, but I'm new to DAX and haven't quite figured out where to put this additional context. How would y'all suggest I update my calculation?

 

Thank you!

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @KCroninKrein 
Try to add a calculated column   with Dax formula:

PreviousDateRevenue = CALCULATE( SUM('Table'[Opportunity_Revenue]), FILTER( 'Table', 'Table'[Line_Of_Business] = EARLIER('Table'[Line_Of_Business]) && 'Table'[Date] = EARLIER('Table'[Date]) - 7 ) )

Ritaf1983_0-1687489886131.png

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Please find attached my PBI file.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ritaf1983
Super User
Super User

Hi @KCroninKrein 
Try to add a calculated column   with Dax formula:

PreviousDateRevenue = CALCULATE( SUM('Table'[Opportunity_Revenue]), FILTER( 'Table', 'Table'[Line_Of_Business] = EARLIER('Table'[Line_Of_Business]) && 'Table'[Date] = EARLIER('Table'[Date]) - 7 ) )

Ritaf1983_0-1687489886131.png

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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