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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
daniel_kusmider
New Member

Calculating difference to previous row

Hi,

 

I'm trying to duplicate in Power BI calculation that's easly done in Excel in a Pivot Table - % diff to previous visible row.

In a Pivot Table you can just choose Show Values as % Difference from... and choose <previous>.

This calculates in real time as I filter data using Slicers.

I've tried replicating that in Power BI, but I have no clue of how to do it.

 

Data look like this:

daniel_kusmider_2-1641814862938.png

I have 4 categories: Leads[Age], Leads[Sex], Leads[Lead Type] and Leads[Product] (in each category there are couple different values possible) and dates in End of Week by which I need to summarise Leads values.

 

In the end I need a table/matrix listed by dates from End of Week.

In the first column I need summarised values of Leads and in the second % difference from previous row and for it to be calculated as somebody filters the report by categories listed above or by date.

 

Here's how the end result looks like in Excel's Pivot Table:

daniel_kusmider_3-1641815184060.png

 

First column's easy but if anyone could help with the second I'd realy appreciate it.

 

 

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

Hi, @daniel_kusmider 

Try to create measures like below:

SUM = SUM('Table'[Leads])
ThisWeek = 
CALCULATE(
    [SUM],
    FILTER(
        ALLSELECTED('Table'),
        'Table'[End of Week]=MAX('Table'[End of Week])
    )
)
LastWeek = 
CALCULATE(
    [SUM],
    FILTER(
        ALLSELECTED('Table'),
        'Table'[End of Week]=MAX('Table'[End of Week])-7
    )
)
LeadDiff% = 
DIVIDE(
    [ThisWeek]-[LastWeek],
    [LastWeek]
)

Result:

vangzhengmsft_0-1642041045267.png

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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

View solution in original post

6 REPLIES 6
v-angzheng-msft
Community Support
Community Support

Hi, @daniel_kusmider 

Try to create measures like below:

SUM = SUM('Table'[Leads])
ThisWeek = 
CALCULATE(
    [SUM],
    FILTER(
        ALLSELECTED('Table'),
        'Table'[End of Week]=MAX('Table'[End of Week])
    )
)
LastWeek = 
CALCULATE(
    [SUM],
    FILTER(
        ALLSELECTED('Table'),
        'Table'[End of Week]=MAX('Table'[End of Week])-7
    )
)
LeadDiff% = 
DIVIDE(
    [ThisWeek]-[LastWeek],
    [LastWeek]
)

Result:

vangzhengmsft_0-1642041045267.png

Please refer to the attachment below for details. Hope this helps.

 

 

Best Regards,
Community Support Team _ Zeon Zheng

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

Thanks @v-angzheng-msft,

That's exactly what I needed.

 

I actualy found a solution on my own on Power Query level but this is way better.

smpa01
Community Champion
Community Champion

@daniel_kusmider  provide sample data/pbix?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
amitchandak
Super User
Super User

@daniel_kusmider , You need to create a date table with weekend date and try measure like given below .

 

new columns  in date /week table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

 

measures
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
Last year Week= CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Thanks @amitchandak,

 

That's a step forward 😉

To what you said I added one measure:

% Leads Diff = IFERROR((Leads[This Week] - Leads[Last Week])/Leads[Last Week], blank())
and this one I showed in a table next to summarized Leads quantity:
daniel_kusmider_0-1641819810514.png

 

Now the question is how to make it interactive with slicers filtering the table.

As you can see below when I use any filters/slicers percentage values make no sence because they are calculated based on a total value for that week:

daniel_kusmider_1-1641819849977.png

 


 

Hi,

Share the link from where i can download your PBI file.  Clearly show the problem there.


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

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.