Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Yaa_D
Frequent Visitor

'Working on it' hangs when combining multiple calculation into one column

Hi All, 
I have a specific calculation that works OK when seperated to different columns, but hangs when trying to combine it all into one column.

The specifics

I have a table that gets updated weekly that have the following columns: fileDate, id, total.
In order to get a monthly total for each id, first, I'm calclating the fileDate 4 weeks ago (previousDate).
To avoid 'missing' new id's, or old id's with no new activity - if the id in previousDate does not exist, I'm using the second-to-max date in which the id is found (alternateDate).
Finally I use this date to LOOKUPVALUE the old total to subtract from the total for each fileDate.

When this is seperated to two different columns as follows it works with no issues :

First column: determins which date to use for the id

.dateChoice =
VAR previousDate = MAXX(FILTER(ALL('table1'), 'table1'[fileDate] <= ('table1'[fileDate])-28), 'table1'[fileDate])
VAR alternateDate = CALCULATE(MAX('table1'[fileDate]), ALLEXCEPT('table1','table1'[id]),'table1'[isMaxDate] = FALSE())

RETURN
IF(previousDate <> 0 , previousDate,
IF(aslternateDate <> 0 , aslternateDate, 'table1'[fileDate]))

 Second colum: LOOKUPVALUE for total using the date in the first column and subtract: 

totalDiff = 
VAR previousTotal = LOOKUPVALUE('table1'[total], 'table1'[fileDate], 'table1'[dateChoice], 'table1'[id], 'table1'[id])
RETURN
'table1'[total] - previousTotal


When I try to combine them into a single colum I get 'Working on it' stuck forever (I tried waiting 45 minuts before giving up)

VAR previousDate = MAXX(FILTER(ALL('table1'), 'table1'[fileDate] <= ('table1'[fileDate])-28), 'table1'[fileDate])
VAR alternateDate = CALCULATE(MAX('table1'[fileDate]), ALLEXCEPT('table1','table1'[id]),'table1'[isMaxDate] = FALSE())
VAR dateChoice = IF(previousDate <> 0 , previousDate,
IF(alternateDate <> 0 , alternateDate, 'table1'[fileDate]))

VAR previousTotal = LOOKUPVALUE('table1'[total],'table1'[fileDate], dateChoice, 'table1'[id], 'table1'[id])

RETURN 'table1'[total] - previousTotal

 

I guess I have two questions here
1 - What am I missing here? Since my table already has ~80 columns I really prefer to keep this number as low as possible.

2 - Is there a way to 'cancel' when 'Working on it' hangs without killing the task? This was the first time this happened to me and it was quite painful 🙂 

Thank you!

3 REPLIES 3
johnt75
Super User
Super User

Rather than using MAX and LOOKUPVALUE, just use TOPN

Total diff =
var currentTotal = 'table1'[total]
var currentDate = 'table1'[fileDate]
var prevTotal = SELECTCOLUMNS( TOPN(1, FILTER( ALLEXCEPT( 'table1', 'table1'[id]), 
   'table1'[fileDate] <= currentDate - 28 ), 'table1[fileDate], DESC), "@val", 'table1[total])
return currentTotal - prevTotal
Yaa_D
Frequent Visitor

Thank you for the reply! I really have a lot to learn in Power BI, most of the time I'm just using the tools I already know that do the job.
When trying the solution you offered I get the error "A circular dependency was detected" on Total diff column, do you have any thoughts on why this is happening?
Thanks again!

its possible that the column itself is being included in the TOPN calculations, try replacing that line with

var prevTotal = SELECTCOLUMNS( TOPN(1, SELECTCOLUMNS(
   FILTER( ALLEXCEPT( 'table1', 'table1'[id]), 
   'table1'[fileDate] <= currentDate - 28 ), 
   "@fileDate", 'table1[fileDate], "@value", 'table1[total])
@fileDate, DESC), "@val", [@value])

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.