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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.