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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AnshulGupta
Helper I
Helper I

How to find difference between first date value Vs the last date value for each of the item?

I have business forecast every month appended as one table; Below is one extremely simplified example:

DateSalesPersonItemValue
5/1/2020ABCMM100
8/1/2020ABCMM30
8/1/2020XYZNN50
9/5/2020ABCQQ60
9/5/2020XYZNN70

 

What I would like to do is to find the delta forecast for different fields whether here SalesPerson Or Item, between First and the Last Forecast. So, as an example, for SalesPerson it would look like:

SalesPersonFirst Day ForecastLast Day ForecastDifference
ABC10060-40
XYZ07070
TOTAL10013030

 

Similar may go for Item or it could be combination of SalesPerson & Item as well. Of course, actual table has tons of other fields and any combination may be needed in the resulting table to see what/who is gaining or is in loss, between first and last date.

I see lot of nice solutions but either they mostly seem to work on total (not individual row item) OR I get values on first available date (so, I don't see 0 for XYZ on First day forecast as in above table) or I get the total of all dates; none of these would work for me though.

 

Your expert help is deeply appreciated.

1 ACCEPTED SOLUTION

@AnshulGupta , please find the attached file an after signature

 

check for First First and Last Last measures in table

 

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@AnshulGupta , Try like

 

First Day Forecast = if(min(Table[Date]) =max(Table[Date]),0 , firstnonblankvalue(Table[Date],max(Table[Value])))
Last Day Forecast= lastnonblankvalue(Table[Date],max(Table[Value])))
diff = [Last Day Forecast] -[First Day Forecast]

 

or with row context

 

First Day Forecast = sumx(Values(Table[SalesPerson]), if(min(Table[Date]) =max(Table[Date]),0 , firstnonblankvalue(Table[Date],max(Table[Value]))))
Last Day Forecast = sumx(Values(Table[SalesPerson]), lastnonblankvalue(Table[Date],max(Table[Value]))))
diff = sumx(Values(Table[SalesPerson]),[Last Day Forecast] -[First Day Forecast])

Sorry, doesn't work. Same issue as reported to Greg
- XYZ on First Day should come 0 but it picks the first available value the next day as 50. I already raised concern on that in original query (see expected table in original query)

 

I need a result table which looks like in my query

@AnshulGupta , please find the attached file an after signature

 

check for First First and Last Last measures in table

 

Works Great. Thank you so much!!!

Greg_Deckler
Super User
Super User

@AnshulGupta I did this in three measures:

First Day = 
    VAR __SalesPerson = MAX('Table (19)'[SalesPerson])
    VAR __Min = MIN('Table (19)'[Date])
RETURN
    SUMX(FILTER(ALL('Table (19)'),[SalesPerson]=__SalesPerson && [Date]=__Min),[Value])



Last Day = 
    VAR __SalesPerson = MAX('Table (19)'[SalesPerson])
    VAR __Max = MAX('Table (19)'[Date])
RETURN
    SUMX(FILTER(ALL('Table (19)'),[SalesPerson]=__SalesPerson && [Date]=__Max),[Value])



Forecast Difference = [Last Day] - [First Day]

PBIX is attached after sig. Table (19), Page 19. Note, if you are doing this to prove that all sales people lie, that's already a given. 😛

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thank you so much. 

 

Unfortunately, I see 3 trouble here

1) XYZ on First Day should come 0 but it picks the first available value the next day as 50. I already raised concern on that in original query (see expected table in original query)

2) Total is not right either on First Day (comes blank) or on last day (comes max) (see expected table in original query)

3) This is only for SalesPerson. I would at least in this simplified table need for item as well. But in actual table I have many different fields. It would be quite cumbersome looking to have some 20 items define into variables and then to use them in Return if condition

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors