Forum Discussion
cursty
1 year agoFrequent Visitor
Calculations with virtual table
Hello everyone, I am working with expenses dataset. This dataset contains 4 columns: the unique id, item id (which can appear multiple times in case few payments have been made for the same item)...
- Anonymous1 year ago
Thanks for the reply from lbendlin and Greg_Deckler, please allow me to provide another insight.
Hi cursty ,
Please try the following dax.Perc_Rank = VAR _tb = CALCULATETABLE(SUMMARIZECOLUMNS('Expenses'[item_id],"Expense",[Expenses]),ALL()) VAR _expenses = VALUE([Expenses]) VAR _lower = IF(COUNTROWS(FILTER(_tb, [Expense]<_expenses))=BLANK(),0,COUNTROWS(FILTER(_tb, [Expense]<_expenses))) VAR _higher = IF(COUNTROWS(FILTER(_tb, [Expense]>_expenses))=BLANK(),0,COUNTROWS(FILTER(_tb, [Expense]>_expenses))) RETURN DIVIDE(_lower,_higher+_lower,0)
The result is as follows, hopefully it will meet your needs.
Please see the attached pbix for reference.
Best Regards,
Dengliang Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin
1 year agoSuper User
Greg_Deckler Did you cover that in your mapping table?
cursty
1 year agoFrequent Visitor
I am not sure if I understood your question, but for this measure I didn't use any mapping besides Calendar Table, which is needed to define the dates range.
Below is more simple formula with RANKX function (user for var 'ranking' which is returning me 1 for every item on the list)
Perc_Rank2 =
var maxdt = max('Calendar'[Date])
var mindt = edate(maxdt,-36)+1
var items = SUMMARIZE(FILTER(Expenses, Expenses[payment_date] IN CALENDAR(mindt,maxdt)), Expenses[item_id], "Value", SUM(Expenses[paid_amount]))
var currentvalue = CALCULATE(SUM(Expenses[paid_amount]), Expenses[payment_date] IN CALENDAR(mindt, maxdt))
var total = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER(ALLSELECTED(Expenses), Expenses[payment_date] IN CALENDAR(mindt, maxdt)), "UniqueID", Expenses[item_id])))
var ranking = RANKX(items, currentvalue,,ASC)
RETURN DIVIDE(ranking, total)*100