Forum Discussion

PowerDigitize_1's avatar
PowerDigitize_1
Frequent Visitor
2 years ago

Incorrect Column Sub Totals

Hi, 

 

I am getting incorrect column sub totals in matrix. Tried with a simple table as well, still the totals are incorrect. 

Have an employee master, store master, product master, target master and sales transaction table.

Each product belongs to a category. Each employee belongs to a store and category. 

Example: Employee John belongs to category Mobile in Store XYZ. 

 

If a target of a category is achieved, all employees within that category should receive an incentive and this is to be doubled if 2nd day also the target is met. I am able to get the values, however in doing so, the column sub totals in the matrix then shows incorrect totals. 

 

CDay = Current Day

PDay = Previous Day

 

The formula also checks if its 1st of the month. If so, then double incentive does not apply on 1st. 

 

Below is my DAX formula:

 

Salespersonincentiveactual = 
var CDay=CALCULATE(SUM('Daily Sales Transaction by employee'[SalespersonIncentive]))
var PDDay= CALCULATE(SUM('Daily Sales Transaction by employee'[SalespersonIncentive]),
            DATEADD('Calendar'[Date],-1,DAY))
var Final=
If(MAX('Calendar'[Day]) = 1, CDay,
IF
(
    PDDay>0 && CDay>0,CDay*2,CDay
)
)
RETURN IF(Final=0,BLANK(),Final)

 

Tried summarize as well, still didnt work - 

 

SalespersonIncentiveActual = 
SUMX(
    SUMMARIZE('Calendar', 'Calendar'[Date]),
    VAR CDay = CALCULATE(SUM('Daily Sales Transaction by employee'[SalespersonIncentive]))
    VAR PDDay = CALCULATE(SUM('Daily Sales Transaction by employee'[SalespersonIncentive]), DATEADD('Calendar'[Date], -1, DAY))
    VAR Final = IF(MAX('Calendar'[Day]) = 1, CDay, IF(PDDay > 0 && CDay > 0, CDay * 2, CDay))
    RETURN IF(Final = 0, BLANK(), Final)
)

 

Kindly advise.

amitchandak Greg_Deckler parry2k