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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Joey2022
Regular Visitor

Calculated column to show difference value btw rows

Hi there! 

I need a favor from you guys, experts. I stucked in the matter for weeks. Pls kindly help me out.

The matter is:

I want to find the difference value of sale btw 2 days as:

DateSaleAmountDifferenceSA
D1Sum1 
D2Sum2Sum2-Sum1
D3Sum3Sum3-Sum2

 

The input Data looked like:

DateSaleAmount
D1S1
D1S2
D2S3
D2S4
D2S5
D3S6

 

Joey

2 ACCEPTED SOLUTIONS
Ashish_Mathur
Super User
Super User

Hi,

Try this

  1. Create a Calendar Table and build a relationship from the Date column of your Data Table to the Date column of the Calendar Table
  2. To your visual, drag Date from the Calendar Table.
  3. Write these measures:

Sales = sum(Data[SaleAmount])

Previous day sales = calculate([Sales],previousday(Calendar[Date]))

Delta = [Sales]-[Previous day sales]

Hope this helps.


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

View solution in original post

Hi,

You may download my PBI file from here.

Untitled.png


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

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

Try this

  1. Create a Calendar Table and build a relationship from the Date column of your Data Table to the Date column of the Calendar Table
  2. To your visual, drag Date from the Calendar Table.
  3. Write these measures:

Sales = sum(Data[SaleAmount])

Previous day sales = calculate([Sales],previousday(Calendar[Date]))

Delta = [Sales]-[Previous day sales]

Hope this helps.


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

hi Ashish_Mathur,

 

I still have a issue regarding to the day without data e.g Sunday. I want to find the different btw Monday and last Saturday. So the "previousday" don't work properly in the case. 

Thank you

Joey

Hi,

You may download my PBI file from here.

Untitled.png


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

Hi Ashish Mathur,

 

Thank you for working it out. I still digest your DAX code, not really understand about how to calculate the Previous day and the Sales in the day.

I am trying with my data. It's like a blind puzzle haha doesn't work out as expected.

 

Joey

You are welcome.  If my previous reply helped, please mark it as Answer.


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

Thank you Ashish Mathur.

It really worked the way I expect. I am really appreciate your guide. Very gentle help.

 

Joey

You are welcome.


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

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjFU0lEyNDBQitWBcoxMoRwjkIwxEsfIAJkDU2YM5JiAZGIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, SaleAmount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}, {"SaleAmount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Date"}, {{"SaleAmount", each List.Sum([SaleAmount]), type nullable text}}),
    #"Added Index" = Table.AddIndexColumn(#"Grouped Rows", "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "DifferenceSA", each try [SaleAmount]-#"Added Index"[SaleAmount]{[Index]-1} otherwise null),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    #"Removed Columns"

 

Thank you Verma!

Got your idea with power querry. But seem my data set is quite large for the group row. I would prefer some solution go with DAX

 

Joey

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors