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.
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:
ID | Date of Data | Projected Commitments Cap | ProjectCommitCap_NoNulls |
3189 | 4/1/2019 | $28,252.99 | |
3189 | 2/25/2019 | $28,252.99 | $28,252.99 |
3189 | 1/14/2019 | ||
3189 | 12/24/2018 | $27,820.85 | |
3189 | 11/5/2018 | $27,820.85 | $27,820.85 |
3189 | 10/22/2018 | $28,036.92 | |
3189 | 10/15/2018 | $28,036.92 | $28,036.92 |
2485 | 10/15/2018 | $11,114.51 | |
2485 | 10/9/2018 | $11,114.51 | $11,114.51 |
3189 | 10/9/2018 | ||
3189 | 9/24/2018 | ||
3189 | 9/10/2018 | ||
3189 | 9/4/2018 | $33,100,567.50 | |
3189 | 8/27/2018 | $33,100,567.50 | $33,100,567.50 |
3189 | 8/13/2018 | $31,229.54 | |
3189 | 7/23/2018 | $31,229.54 | $31,229.54 |
3189 | 7/16/2018 | $28,896.80 | |
3189 | 7/9/2018 | $28,896.80 | $28,896.80 |
3189 | 6/25/2018 | $29,790.51 | $29,790.51 |
3189 | 6/18/2018 | $0.00 | |
3189 | 6/11/2018 | $0.00 | $0.00 |
Here is what I want it to look like:
ID | Date of Data | Projected Commitments Cap | ProjectCommitCap_NoNulls |
3189 | 4/1/2019 | $28,252.99 | |
3189 | 2/25/2019 | $28,252.99 | $28,252.99 |
3189 | 1/14/2019 | $27,820.85 | |
3189 | 12/24/2018 | $27,820.85 | |
3189 | 11/5/2018 | $27,820.85 | $27,820.85 |
3189 | 10/22/2018 | $28,036.92 | |
3189 | 10/15/2018 | $28,036.92 | $28,036.92 |
2485 | 10/15/2018 | $11,114.51 | |
2485 | 10/9/2018 | $11,114.51 | $11,114.51 |
3189 | 10/9/2018 | $33,100,567.50 | |
3189 | 9/24/2018 | $33,100,567.50 | |
3189 | 9/10/2018 | $33,100,567.50 | |
3189 | 9/4/2018 | $33,100,567.50 | |
3189 | 8/27/2018 | $33,100,567.50 | $33,100,567.50 |
3189 | 8/13/2018 | $31,229.54 | |
3189 | 7/23/2018 | $31,229.54 | $31,229.54 |
3189 | 7/16/2018 | $28,896.80 | |
3189 | 7/9/2018 | $28,896.80 | $28,896.80 |
3189 | 6/25/2018 | $29,790.51 | $29,790.51 |
3189 | 6/18/2018 | $0.00 | |
3189 | 6/11/2018 | $0.00 | $0.00 |
Thanks! Let me know if i need to provide more detail 🙂
Solved! Go to Solution.
Looping is generally not permitted in DAX. However, I have written some blog articles on simulating looping in DAX that you might find useful:
https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/ba-p/636314
https://community.powerbi.com/t5/Community-Blog/Previous-Value-Recursion-in-DAX/ba-p/638320
Looping is generally not permitted in DAX. However, I have written some blog articles on simulating looping in DAX that you might find useful:
https://community.powerbi.com/t5/Community-Blog/For-and-While-Loops-in-DAX/ba-p/636314
https://community.powerbi.com/t5/Community-Blog/Previous-Value-Recursion-in-DAX/ba-p/638320
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
97 | |
78 | |
64 | |
55 |
User | Count |
---|---|
143 | |
109 | |
89 | |
84 | |
66 |