Forum Discussion
DAX: Generic Measure Formula to Display Value on Top Level Row Element Only in Matrix Visual
TomM_5 , Based on what I got, check if this can help
lifetimeSales =
VAR isTopLevel =
NOT ISFILTERED(dimCustomer[customerKey]) &&
NOT ISFILTERED(dimCalendar[dateKey]) &&
(HASONEVALUE(dimCustomer[accountNumber]) || ISFILTERED(dimCustomer[accountNumber]))
RETURN
IF(
isTopLevel,
CALCULATE(
SUM(factInvoiceSales[invoiceAmt]),
ALLEXCEPT(
factInvoiceSales,
dimCustomer[accountNumber]
)
),
BLANK()
)
amitchandak This formula didn't appear to work for me. When I created a measure with this formula, it calculated the lifetime sales correctly, however, expanding from accountNumber to calendarYear repeated the lifetime sales for each calendarYear row. This formula does appear to remove the result from the grand total row though.
My original measure formula functions correctly in my report, however, I was hoping there was a way to do something more generic to simply detect the top level row that didn't rely on the data itself. So if the business decided that some other column such as country or state/province needed to be inserted above accountNumber, it wouldn't require a different measure or a rewrite of the existing one.
I was hoping to be able to do something like IF(ROWDEPTH() = 1, CALCULATE(SUM(factInvoiceSales[invoiceAmt]),ALLEXCEPT(factInvoiceSales,dimCustomer[accountNumber])),BLANK()) where ROWDEPTH would be a function (built-in or otherwise) that determines at what level of the table the measure calculation is occuring.....kind of like returning the depth of a node in a binary tree in Java or C++. I looked at the PATH functions thinking maybe something like PATHLENGTH would tell me if I was at the top level, but I don't understand them well enough from the documentation to know whether anything like that would actually work.