cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

------------------------------------------------------

 

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

 

"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

Announcements
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: