cancel
Showing results for
Did you mean:  Helper I

## Calculate totals based on switch true groupings

Hello,

I have the following formula which categorises aging of receivables based on the overdue days

Aging Buckets = SWITCH(TRUE(),
AND([Days Over] =0, [Days Over]>=0), "Current",
AND([Days Over]>=1, [Days Over]<=30), "Age 1 -30 Days",
AND([Days Over]>=31, [Days Over]<=60), "Age 31 -60 Days",
AND([Days Over]>=61, [Days Over]<=90), " Age 61 -90 Days",
"Age 90 Days +"

I would then like to calculate measures for  the total amount for each bucket using some logic, for example, to calculate the total for all invoices with less than 31 days overdue, but I get errors The end goal would to have measures for total overdue, 30 60 days overdue, 90 days overdue etc that i can easily change depending on the range overdue days we want to look at.  Thanks for your help!
1 ACCEPTED SOLUTION  Super User

@watje255_ju
Yes you can. Please refer to the original reply updated as requested. Have a good day!

11 REPLIES 11  Super User

would you please share a screenshot of your visual?  Helper I

Hi @tamerj1

Thanks also for your help, here is the current table, you can see the buckets from the switch true formula, but ideally i would be able to create measures off the buckets or Days Over formula, e.g. a measure that calculates the sum of either all invoices aged over 31 days, or the sum of the buckets

Age 61 -90 Days",
"Age 90 Days +" etc.

My days over formula is dynamic based on the selected reporting day
Days Over =
IF( AND( [Invoice Date] < [Selected Date], [Due Date] < [Selected Date] ),
DATEDIFF( [Due Date], [Selected Date], DAY ),
0 ) Is there anywhere to load up the test PBIX file in this forum it might be helpful? Thanks again!  Super User

You can upload and share a download link. I believe there is a better approach to this sibject. I will look into it and get back to you by tomorrow morning. Thank you  Helper I

Hi @tamerj1  https://1drv.ms/u/s!As8wMr9_bgGrgV0CJ2U8MflBJ8nU?e=CB6GaJ here is the PBIX link - thanks again for your help. let me know if this doesnt work! Cheers  Super User

Hi @watje255_ju
Here is the sample file with the solution https://we.tl/t-FpKkxGhFRd

First you need to to create a filter table containing the buckets and the ranges. ``````Buckets =
SELECTCOLUMNS (
{
( "Current", 0, 1 ), ( "Age 1 -30 Days", 1, 30 ),
( "Age 31 -60 Days", 30, 60 ), ( "Age 61 -90 Days", 60, 90 ),
( "Age 90 Days +", 90, 9999999 )
},
"Bucket", [Value1],
"From", [Value2],
"To", [Value3]
)``````

Then use this version of the Days Over measure "[Days Over 2]" ``````Days Over 2 =
VAR SelectedDate = [Selected Date]
RETURN
SUMX (
VALUES ( FactAccountsReceivable[Voucher] ),
VAR InvoiceDate = CALCULATE ( MIN ( FactAccountsReceivable[Document Date] ) )
VAR DueDate = CALCULATE ( MIN ( FactAccountsReceivable[Due Date] ) )
RETURN
IF (
InvoiceDate < SelectedDate
&& DueDate < SelectedDate,
DATEDIFF ( DueDate, SelectedDate, DAY ),
0
)
)``````

Finally create the Amount per Bucket measure that returns the Amount based on the Buket and the selected date. ``````Amount Per Bucket =
SUMX (
VALUES ( Buckets[Bucket] ),
CALCULATE (
VAR FromDays = SELECTEDVALUE ( Buckets[From] )
VAR ToDays = SELECTEDVALUE ( Buckets[To] )
VAR Result =
CALCULATE (
[Amount],
FILTER (
VALUES ( FactAccountsReceivable[Voucher] ),
VAR DaysOver = [Days Over 2]
RETURN
DaysOver > FromDays
&& DaysOver <= ToDays
)
)
RETURN
Result
)
)``````  Helper I

Hi @tamerj1 , this is awesome, thank you very much! appreciate the detailed answer breaking out the logic - and the buckets filter table is an awesome way to be able to group the aging buckets as the manager wants which is perfect. Is there anyway to get the grand total to calculate at all?   Helper I

Hi @tamerj1 , that's working perfectly, thank you very much! Really appreciate your help!  Super User

@watje255_ju
Yes you can. Please refer to the original reply updated as requested. Have a good day! Frequent Visitor

Hello @watje255_ju !

As you create the "Aging Buckets" column, it will be filled with strings. Later in you IF(), you compare the "Aging Buckets" to numbers. This will cause an error. Try doing

``Less than 31 Days = CALCULATE('Aging Measures'[Amount], IF('Aging Measures'[Days Over], [Amount], 0))``  Helper I

Hi Amin,

Thanks so much for your reply! I still get the same error "A function 'PLACEHOLDER' has been used in a True/False expression that is used as a table filter expression. This is not allowed." Is there a way to upload the PBIX file here? Much appreciated!  Helper I

sorry forgot to tag @AminAlian   