Forum Discussion
pani_victoria
Helper III
1 year agosum 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 ...
rohit1991
Super User
1 year agoHi 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
1 year agoHi
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?