Forum Discussion
row total Problem for Aging Report
- 2 years ago
Hi Anonymous
After applying the DAX you provided, the Total at the bottom is summing up the values of Item group which has been correct so the Total is showing right values, however the values at Product level is still the same after I changed your DAX from Product level to Item level.
Also at last in SUMX function, it's giving error to pass same value as the current measure name.
I modified the DAX you provided to this
Z_Aging Qty 31-60 Product2 =VAR SaleSum =CALCULATE(SUM('Aging Main'[Sold Qty]),FILTER('Aging Main', 'Aging Main'[Date] <= MAX(DateTable[Date])))VAR Purch =CALCULATE(SUM('Aging Main'[Purchase Qty]),FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 60))VAR PurchSum =CALCULATE(SUM('Aging Main'[Purchase Qty]),FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 30 && (MAX(DateTable[Date]) - 'Aging Main'[Date]) <= 60))VAR Sale = -SaleSum // Sold qty had negative valuesVAR IsItemLevel = HASONEVALUE('Aging Main'[Item Group])RETURNIF(IsItemLevel,IF(Purch >= Sale,IF(ISBLANK(PurchSum), 0, PurchSum),VAR SaleSum1 = Sale - PurchVAR AgingQty =IF(SaleSum1 >= PurchSum,0,IF(ISBLANK(PurchSum - SaleSum1), 0, PurchSum - SaleSum1))RETURN AgingQty),SUMX(VALUES('Aging Main'[Item Group]),[Z_Aging Qty 31-60]))
Hi Aditya_Mishra1 ,
It seems that the issue you're experiencing is related to the context in which the DAX calculations are being performed, especially when aggregating data at the Item Group level.
In Power BI, when using a matrix visual, the calculations for subtotals and grand totals can sometimes behave differently than expected because they are calculated based on the current context, which includes all filters and slicers that are applied to the visual.
To address this issue, you may need to modify your DAX measure to ensure that it calculates correctly at all levels of aggregation. One common approach is to use the `HASONEVALUE` function to determine if the calculation is being done at the product level or at a higher level of aggregation, such as the Item Group level, and then adjust the calculation accordingly.
Z_Aging Qty 31-60 =
VAR SaleSum =
CALCULATE(
SUM('Aging Main'[Sold Qty]),
FILTER('Aging Main', 'Aging Main'[Date] <= MAX(DateTable[Date]))
)
VAR Purch =
CALCULATE(
SUM('Aging Main'[Purchase Qty]),
FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 60)
)
VAR PurchSum =
CALCULATE(
SUM('Aging Main'[Purchase Qty]),
FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 30 && (MAX(DateTable[Date]) - 'Aging Main'[Date]) <= 60)
)
VAR Sale = -SaleSum // Sold qty had negative values
VAR IsProductLevel = HASONEVALUE('Product'[ProductName])
RETURN
IF(
IsProductLevel,
IF(
Purch >= Sale,
IF(ISBLANK(PurchSum), 0, PurchSum),
VAR SaleSum1 = Sale - Purch
VAR AgingQty =
IF(
SaleSum1 >= PurchSum,
0,
IF(ISBLANK(PurchSum - SaleSum1), 0, PurchSum - SaleSum1)
)
RETURN AgingQty
),
SUMX(
VALUES('Product'[ProductName]),
[Z_Aging Qty 31-60]
)
)
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ Rongtie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Aditya_Mishra12 years agoFrequent Visitor
Hi Anonymous
After applying the DAX you provided, the Total at the bottom is summing up the values of Item group which has been correct so the Total is showing right values, however the values at Product level is still the same after I changed your DAX from Product level to Item level.
Also at last in SUMX function, it's giving error to pass same value as the current measure name.
I modified the DAX you provided to this
Z_Aging Qty 31-60 Product2 =VAR SaleSum =CALCULATE(SUM('Aging Main'[Sold Qty]),FILTER('Aging Main', 'Aging Main'[Date] <= MAX(DateTable[Date])))VAR Purch =CALCULATE(SUM('Aging Main'[Purchase Qty]),FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 60))VAR PurchSum =CALCULATE(SUM('Aging Main'[Purchase Qty]),FILTER('Aging Main', (MAX(DateTable[Date]) - 'Aging Main'[Date]) > 30 && (MAX(DateTable[Date]) - 'Aging Main'[Date]) <= 60))VAR Sale = -SaleSum // Sold qty had negative valuesVAR IsItemLevel = HASONEVALUE('Aging Main'[Item Group])RETURNIF(IsItemLevel,IF(Purch >= Sale,IF(ISBLANK(PurchSum), 0, PurchSum),VAR SaleSum1 = Sale - PurchVAR AgingQty =IF(SaleSum1 >= PurchSum,0,IF(ISBLANK(PurchSum - SaleSum1), 0, PurchSum - SaleSum1))RETURN AgingQty),SUMX(VALUES('Aging Main'[Item Group]),[Z_Aging Qty 31-60]))