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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Replace values in column

Hello everyone.
My dataset is as follows

 

Server_name       Number_of_licenses

------------------------------------------

Server1                       1800

Server2                         null

Server3                         null

Server4                          200

Server5                          null

Server6                          650

Server7                          1120

 

What I have been trying to achieve is replace the null with the value right above, by dividing "value" to the number of nulls right below + 1. Also, the "value" should be replace with the result of the division.

For instance, the nulls below 1800 should be replaced by 600 (1800/3) and 1800 itself should also be replaced with 600.

 

The dataset after applying the formula should be:

 

Server_name       Number_of_licenses

------------------------------------------

Server1                       600

Server2                       600

Server3                       600

Server4                       100

Server5                       100

Server6                       650

Server7                      1120

 

Any ideas on how can I achieve this? I've been trying for some days already and I don't see any solution to this.

 

Thanks in advance.
Vlad

1 ACCEPTED SOLUTION
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

First create a calculated column for ranking:

 

Rank = RANKX('Table'; 'Table'[Server_name];; ASC)
 
After create another calculted column for adjust the values:
 
Number_of_Licenses_2 =
VAR _rank = 'Table'[Rank]
VAR _newRank = CALCULATE(MIN('Table'[Rank]); FILTER(ALL('Table'); 'Table'[Rank] > _rank && ISBLANK('Table'[Number_of_licenses]) = FALSE()))
VAR _newRank2 = CALCULATE(MAX('Table'[Rank]); FILTER(ALL('Table'); 'Table'[Rank] <= _rank && ISBLANK('Table'[Number_of_licenses]) = FALSE()))
VAR _value = CALCULATE(DISTINCT('Table'[Number_of_licenses]); FILTER(ALL('Table'); 'Table'[Rank] = _newRank2))
RETURN IF(_newRank - _newRank2 > 0; DIVIDE(_value; _newRank - _newRank2; 0); 'Table'[Number_of_licenses])
 
I hope it helps.
 
If you consider it as a solution, please mark as solution and kudos.
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



View solution in original post

1 REPLY 1
camargos88
Community Champion
Community Champion

Hi @Anonymous ,

 

First create a calculated column for ranking:

 

Rank = RANKX('Table'; 'Table'[Server_name];; ASC)
 
After create another calculted column for adjust the values:
 
Number_of_Licenses_2 =
VAR _rank = 'Table'[Rank]
VAR _newRank = CALCULATE(MIN('Table'[Rank]); FILTER(ALL('Table'); 'Table'[Rank] > _rank && ISBLANK('Table'[Number_of_licenses]) = FALSE()))
VAR _newRank2 = CALCULATE(MAX('Table'[Rank]); FILTER(ALL('Table'); 'Table'[Rank] <= _rank && ISBLANK('Table'[Number_of_licenses]) = FALSE()))
VAR _value = CALCULATE(DISTINCT('Table'[Number_of_licenses]); FILTER(ALL('Table'); 'Table'[Rank] = _newRank2))
RETURN IF(_newRank - _newRank2 > 0; DIVIDE(_value; _newRank - _newRank2; 0); 'Table'[Number_of_licenses])
 
I hope it helps.
 
If you consider it as a solution, please mark as solution and kudos.
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.