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
ING_BT
Helper I
Helper I

Conditional Sum - Evaluate only after date for each Company

Hello! 

 

I'm trying to create a conditional sum of sales such as: 

 

I have sales data for Company A, B, C and D for the whole 2021 year. However, I have in another table dates from which I should be calculating the Sales such as: 

Company A: calculate only after 10.02.2021

Company B: calculate only after 15.06.2021

Company C: calculate only after 17.08.2021

Company 😧 calculate only after 02.10.2021

 

This table is connected to the Sales tables with Company names, Dates and number of sales

And is connected to the Date table (also connected to sales tables). 

 

How can I create a Sum measure, to ingnore for each companies the Sales before the related dates? 

 

I'm sure the solution is simple, but I can't wrap my head around it! 

 

Thank you so much for your help.

 

Best,

BT. 

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

Consider this solution

 

create a company table with

company id, company name, afterdate

create a sales table with

date, company id, value

 

create a 1:m relationship from company[companyid] to sales[companyid]

 

create measure

 

Aftersales =
VAR myafterdate = SELECTEDVALUE(Company[afterdate])
RETURN
CALCULATE(
SUM(sales[value],
Sales[date] > myafterdate
)
 
Drag company[company name] and [Aftersales] to a table visual
and it will give you the correct answer.
 
Please click thumbbs up and Accept as solution, thank you 

View solution in original post

4 REPLIES 4
speedramps
Super User
Super User

Consider this solution

 

create a company table with

company id, company name, afterdate

create a sales table with

date, company id, value

 

create a 1:m relationship from company[companyid] to sales[companyid]

 

create measure

 

Aftersales =
VAR myafterdate = SELECTEDVALUE(Company[afterdate])
RETURN
CALCULATE(
SUM(sales[value],
Sales[date] > myafterdate
)
 
Drag company[company name] and [Aftersales] to a table visual
and it will give you the correct answer.
 
Please click thumbbs up and Accept as solution, thank you 

However, when I put Company and this measure next to normal sum, it will show me another value as expexted for a company where we count after the date; but the sum of those two will be the same. 
How can we include "sum only after this date" if we look at the total of the measure with a slicer that selects all the companies ? 

I don't know if it is clear?

Works perfectly! thank you 🙂 

Greg_Deckler
Super User
Super User

@ING_BT This may help. Specifically SUMIF

S Excel to DAX Translation - Microsoft Power BI Community


@ 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...

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.