Forum Discussion
sum sales by a specific condition
Colleagues, hello!
I have dataset
How can I calculate add sales site?
These are sales with an empty site field, but with the same document number, where the site is not empty
Please, help me )
4 Replies
- rohit1991
Super User
Hi pani_victoria
To calculate the "add sales site" column in Power BI, you need to sum sales where the site field is empty but match document numbers where the site is not empty.Solution in DAX:
You can create a calculated column using this DAX formula:
Add Sales Site = VAR SalesWithSite = CALCULATE( SUM(YourTable[sales]), YourTable[site] <> BLANK() ) VAR SalesWithoutSite = CALCULATE( SUM(YourTable[sales]), YourTable[site] = BLANK() ) RETURN IF(YourTable[site] = BLANK(), SalesWithSite, BLANK())Explanation:
- SalesWithSite: Calculates the total sales where the site is NOT blank.
- SalesWithoutSite: Calculates sales where the site is blank but has the same document number where a site exists.
- Final Return: Assigns the matching sales value to the row where site is blank.
- pani_victoria
Helper III
Hi
VAR SalesWithoutSite = CALCULATE( SUM(YourTable[sales]), YourTable[site] = BLANK()2. SalesWithoutSite: Calculates sales where the site is blank but has the same document number where a site exists.
The id doc is not taken anywhere in the formula. Is this true?
- Bibiano_Geraldo
Super User
- pani_victoria
Helper III
Hi
I have Internet Sales = this is the sum of the sales where the site <> is empty
And there are additional sales = this is the sum the sales that have the same document number as the site sales, but their site = empty. That's the sum I need to calculate.