Forum Discussion

Mathias_W's avatar
Mathias_W
Regular Visitor
6 years ago
Solved

Looping a working DAX function in a calculated column

Hi All,

I have a function that will look at a null field in column "Project Commit Cap" and lookup the value with the same ID and the next earlier date and give column "Project Commit Cap NoNulls" that value. DAX does not do it recursively so if there are 2 null values in a row I get a blank. In another language a simple while loop (while value is null do: XYZ) would solve this, but DAX does not support For/While loops?

 

How can i get the working DAX function to apply the filled in values and keep running until there are no more nulls?

Optionally how can i brute force it to run X number of times (maybe 10)? it wouldn't be a pretty solution but will get the job done

Example tables below are filtered to show only one 2 IDs, records of different IDs are between the records shown here so I cant do an excel-like function "take value from row below"

 

Here is the dax function that will fill in the previous value:

 

'ProjectCommitCap_NoNulls =
if(isblank('Project Story Data'[Projected Commitments Cap]),
LOOKUPVALUE('Project Story Data'[Projected Commitments Cap],'Project Story Data'[ID],'Project Story Data'[ID],
'Project Story Data'[Date of Data],CALCULATE(MAX('Project Story Data'[Date of Data]),FILTER('Project Story Data','Project Story Data'[ID]=EARLIER('Project Story Data'[ID])&&'Project Story Data'[Date of Data]<EARLIER('Project Story Data'[Date of Data])))),
'Project Story Data'[Projected Commitments Cap])'

 

Here is what the table looks like currently (only filling in one blank value gap:

IDDate of DataProjected Commitments CapProjectCommitCap_NoNulls
31894/1/2019 $28,252.99
31892/25/2019$28,252.99$28,252.99
31891/14/2019  
318912/24/2018 $27,820.85
318911/5/2018$27,820.85$27,820.85
318910/22/2018 $28,036.92
318910/15/2018$28,036.92$28,036.92
248510/15/2018 $11,114.51
248510/9/2018$11,114.51$11,114.51
318910/9/2018  
31899/24/2018  
31899/10/2018  
31899/4/2018 $33,100,567.50
31898/27/2018$33,100,567.50$33,100,567.50
31898/13/2018 $31,229.54
31897/23/2018$31,229.54$31,229.54
31897/16/2018 $28,896.80
31897/9/2018$28,896.80$28,896.80
31896/25/2018$29,790.51$29,790.51
31896/18/2018 $0.00
31896/11/2018$0.00$0.00


Here is what I want it to look like:

IDDate of DataProjected Commitments CapProjectCommitCap_NoNulls
31894/1/2019 $28,252.99
31892/25/2019$28,252.99$28,252.99
31891/14/2019 $27,820.85
318912/24/2018 $27,820.85
318911/5/2018$27,820.85$27,820.85
318910/22/2018 $28,036.92
318910/15/2018$28,036.92$28,036.92
248510/15/2018 $11,114.51
248510/9/2018$11,114.51$11,114.51
318910/9/2018 $33,100,567.50
31899/24/2018 $33,100,567.50
31899/10/2018 $33,100,567.50
31899/4/2018 $33,100,567.50
31898/27/2018$33,100,567.50$33,100,567.50
31898/13/2018 $31,229.54
31897/23/2018$31,229.54$31,229.54
31897/16/2018 $28,896.80
31897/9/2018$28,896.80$28,896.80
31896/25/2018$29,790.51$29,790.51
31896/18/2018 $0.00
31896/11/2018$0.00$0.00

 

Thanks! Let me know if i need to provide more detail :)