PowerBi DAX equivalent for SUMIFS with current row value as filter -


in excel could, if in table called 'sales' had 4 columns

sales

month, customerid, productid, totalquantity jan,1, car, feb,1, car, 

i add formula:

=sumifs(sales[quantity],sales[customerid],[@[customerid]]) 

that go sales table , sum customerid column filtered customerid of current row formula has been entered.

i attempted replicate in powerbi calculated row can't @ working row reference. comes across like

totalquantity = calculate(sum(sales[quantity]),sales[customerid] = sales[customerid])) 

any idea how equivalent @ working?

i think key function missing earlier. not surprising because has misleading name - means "current row". need filter function in filter parameter of calculate, reset filter context entire table.

so new column function might this:

totalquantity = calculate(sum(sales[quantity]), filter(sales, sales[customerid] = earlier (sales[customerid])))

here's neat example, accessible source site dax formulas:

http://www.powerpivotpro.com/2013/07/writing-a-subtotal-calc-column-aka-the-simplest-use-of-the-earlier-function/

and fwiw here official doco on earlier:

https://msdn.microsoft.com/en-us/library/ee634551.aspx


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -