Showing results for 
Search instead for 
Did you mean: 
anikah Regular Visitor
Regular Visitor

Re: How to calculate the sales difference based on some criteria with DAX query?

Hi Kris,


Your solution works exactly as i need. Great Thank you very much.

However when i applied this formula on my relational data the second MAX(value) is returning wrong, LD date is not matching because of which i am not getting correct sales value within the "Seq" group.


So i have created two columns


 "Firstsales" : as column 1 based on your solution



VAR seq = 'Table'[Seq]
VAR tbl =
    'Table'[Seq] = seq
VAR fd =
VAR startSales =
    FILTER( tbl, 'Table'[BeginDate] = fd),


"Lastsale"  as 2nd column formula as



Lastsale=CALCULATE(MAX('Table'[Sales]),FILTER('Table','Table'[Seq] =EARLIER('Table'[Seq])))


and Then created a 3rd SalesDiff column by ( Lastsale - Firstsale) to get the results as indicated by you. I know this sounds very strange but this is working.


Thanks again for your great help..!





Helpful resources

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Power BI Helps Homeless and Trouble Youth

Power BI Helps Homeless and Trouble Youth

We spoke with Power BI Super User, Greg Deckler, about his charity work

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Top Kudoed Authors
Users Online
Currently online: 393 members 4,024 guests
Please welcome our newest community members: