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

Exclude blank rows from sums

I'm having some problems getting a calculation working and need some assistance.

 

I'm trying to calculate discount for various products YTD. Some  products have a base price and sale price, some just have sale price.

In the event that there is no base price, these products should be excluded from discount sums. Take the following example:

 

ItemSales ValueBase PriceDiscount
Group1€ 4,185.00€ 2,228.5687.79%
          Product 1€ 2,360.00€ 2,228.565.90%
          Product 2€ 1,825.00  

 

As you can see Group 1  discount is calculating: (sum of sales value - sum of base price) / (sum of base price).  Group 1  should not be taking Product 2 into account for cumulative calculations for discount.

 

Here is my Dax formula as is:

 

Total Discount YTD (Actual):=

IF(
     AND(
          CALCULATE(SUM(SalesActualVsForecast[Amount]),DATESYTD(DateDimension[Date]),SalesActualVsForecast[Type]="Actual") <> BLANK(),
         CALCULATE(SUM(SalesActualVsForecast[BasePrice]),DATESYTD(DateDimension[Date]),SalesActualVsForecast[Type]="Actual") <> BLANK()),
DIVIDE(
        (

           CALCULATE(SUM(SalesActualVsForecast[Amount]),DATESYTD(DateDimension[Date]),SalesActualVsForecast[Type]="Actual")
           -CALCULATE(SUM(SalesActualVsForecast[BasePrice]),DATESYTD(DateDimension[Date]),SalesActualVsForecast[Type]="Actual")),
           CALCULATE(SUM(SalesActualVsForecast[BasePrice]),DATESYTD(DateDimension[Date]),SalesActualVsForecast[Type]="Actual")
        )
)

1 ACCEPTED SOLUTION
v-chuncz-msft
Community Support
Community Support

@dimitrishuk,

 

You may try using SUMX Function which returns the sum of an expression evaluated for each row in a table.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@dimitrishuk,

 

You may try using SUMX Function which returns the sum of an expression evaluated for each row in a table.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.