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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Menar
Frequent Visitor

Sum Sales For Last Transaction Date by Customer, Over last 3 Months

Hi everyone !

I am pretty to new to DAX and heavily struggling with this.

I am aiming for a measure that calculates the sum of sales by Customerid only for their last transaction date in the last 3 months.
The last 3 months should depend on the dates filtered. If I select the 20/01/2023 in my date slicer, the measure should scan the period from 20/01/2023 to 20/10/2022 and Sum the Sales for each Customerid for their Last Date in this period.

I still need to be able to slice the data by other fields, like ProductId or Salesagentid.

Here's my sample data :

CustomeridSalesagentidProductIdTransaction DateSales
456300502101/11/2022400
456300502301/11/2022950
456300502701/11/2022900
322300897705/11/2022800
322300897805/11/2022150
322300897105/11/202250
322300897605/11/2022400
111300700715/11/2022150
111300700315/11/2022600
111300700515/11/2022350
322300897412/12/2022550
322300897112/12/2022700
456300564928/12/2022350
456300564328/12/2022600
111300700831/12/2022850
111300700731/12/2022200
111300700931/12/2022350
111300700825/01/202350
111300700725/01/2023950
111300700925/01/2023800
322300897830/01/2023850
322300897930/01/2023700
322300897430/01/20230
456300564302/02/202350
456300564102/02/2023850
456300564802/02/2023200
456300564402/02/2023150


Expected Result If I filter on the 26th of january 2023 :

CustomeridSalesagentidProductIdTransaction DateSales
322300897412/12/2022550
322300897112/12/2022700
456300564928/12/2022350
456300564328/12/2022600
111300700825/01/202350
111300700725/01/2023950
111300700925/01/2023800


The logic is that I only want to show the latest data depending on dates filtered (last date over the last 3 months from max date filtered) for each Customerid.

I did try some measures using DATESINPERIOD, LASTDATE and SUMX but none of that really worked.



Link to Excel file used as source date :
https://www.dropbox.com/scl/fi/sqtgaait9x0psmj7eg72n/Database-sum-sales-by-cust-for-max-date.xlsx?dl...

Link to the PBI file :
https://www.dropbox.com/s/owl1jvjng4h4ik0/Sum%20sales%20per%20customerid%20for%20max%20date.pbix?dl=...


The data model :

Data modelData model

 


Thank you so much in advance for any help, would be much appreciated !

6 REPLIES 6
lbendlin
Super User
Super User

Thank you for providing the sample data.  We may have a slight disagreement on the date format though. Here's my result for Jan 26 2023:

 

lbendlin_0-1683072413504.png

 

You can't use a connected dates table for this exercise.

see attached.

Thank you for your response.

Yes, I am aiming for something like this but the measure should only returns the data from the latest transaction date per customer.
Meaning on Jan 26 2023 filtered, I should only see the data from Jan 25 for customerid 111, from Dec 28 2022 for customerid 456 and from Dec 12 2022 for customerid 322.

Show = 
var m = max(Dates[Date])
var d = CALCULATE(max('Table'[Transaction Date]),ALLEXCEPT('Table','Table'[Customerid]),'Table'[Transaction Date]<=m && 'Table'[Transaction Date]>= EDATE(m,-3))
return if (SELECTEDVALUE('Table'[Transaction Date])=d,1,0)

lbendlin_0-1683116388167.png

 

I see, it does work in the layout you provided, thanks, but it does not intereact with any dates slicer which would come from a date table (because there is no relationship obviously). 

My user has to be able to filter dates on the report through a date slicer ☹️

Plus it seems i can not apply the filter for "Show =1" to the whole report, it has to be done visual by visual.

My user has to be able to filter dates on the report through a date slicer :frowning_face:

They can still do that, but the slicer has to be fed from the disconnected table.

 

Measures can only serve as visual filters. If this is important to you please consider voting for an existing idea or raising a new one at https://ideas.powerbi.com

I see, that's not exactly what i was looking for but thank you for your help!

I'll keep looking to see if this achievable.


Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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