Forum Discussion
Help w/Tricky Issue: Disconnected Table DAX Bucketing
Question: Why can't you just pre-calculate all balances for all accounts for all days you're interested in? Then your measure would be dead simple and lightning fast, as would be the converted amount. But if you try to calculate the balances for every day and every account (and what have you) on the fly... well, that may cost you a lot.
I'm not a fan of the above DAX, either 🙂 It's too complex to say the least. I'm sure "There MUST be a better way," to paraphrase Raymond Hettinger.
- ryan25r95 years ago
Helper I
That's definitely something I started to consider lately. I'm going to look into how to structure that today and I'll follow-up here.
I still think there might be efficiency issues outside of that though. If I comment out this section and the reference to it:
VAR Aged = FILTER( // Filter to dates within the Aging Bucket, based on the Due Date in relation to the As Of Date VALUES('xDate - Document Due'[Document Due Date]), VAR DaysOD = DATEDIFF( 'xDate - Document Due'[Document Due Date], AsOfDate, DAY ) RETURN COUNTROWS( // Second FILTER argument must be a Boolean value FILTER( 'Aging Buckets' , 'Aging Buckets'[Lower Bound] <= DaysOD && DaysOD <= 'Aging Buckets'[Upper Bound] ) ) > 0 )most things appear to go much faster, which seems odd to me.
- ryan25r95 years ago
Helper I
After looking into this, I'm actually a little confused on how to best set this up. Can you elaborate on what you're thinking?
I created a Calculated Column in Collections to store the Rolling Balance. Unfortunately, the measure I wrote actually ended up slower than the original. I still don't know of a way to not need to clear the Collections[As Of Date] filter to get the Outstanding Balance, which likely slows things down.
Am I missing something?
Updated .pbix: drive.google.com/file/d/128rvGqMmCFjvAUBMmr9x06Z1fjStihJW/view?usp=sharing
VAR AsOfDate = MIN( MAX('xAs Of Date'[As Of Date]), TODAY() ) // Earlier of the latest As Of Date in the original filter context or Today. Use MAX so it still works when rolled up to year or when there is no filter applied VAR LastValue = CALCULATETABLE( TOPN( 1 , SUMMARIZE(Collections, Collections[Document Key], Collections[From Document Key], Collections[As Of Date]) , Collections[As Of Date], DESC, Collections[From Document Key], DESC ) , 'xAs Of Date'[As Of Date] <= AsOfDate /*** This section is surprisingly faster, but still slower than the original measure ***/ // , FILTER( ALL(Collections[As Of Date]) // , Collections[As Of Date] <= AsOfDate // ) // , CROSSFILTER('xAs Of Date'[As Of Date], Collections[As Of Date], NONE) ) VAR Balance = CALCULATE( SUM(Collections[RollingFuncAmt]) , LastValue , 'xAs Of Date'[As Of Date] <= AsOfDate // , CROSSFILTER('xAs Of Date'[As Of Date], Collections[As Of Date], NONE) ) VAR Final = IF(ROUNDDOWN(ABS(Balance), 0) = 0, BLANK(), Balance) // Hide 0 Balances & pennies remaining from bad GP data RETURN Final- Anonymous5 years agoNot applicable
You have to pre-calculate the balances not in DAX but in the source system (SQL Server, right?) or in Power Query. Then and only then will it make a lot of sense.
- ryan25r95 years ago
Helper I
Not sure what you mean. I calculated it in SQL as well and it's the same as the DAX Calculated Column.