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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors