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

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.

Reply
ronaldbalza2023
Continued Contributor
Continued Contributor

Adding new column / replace column in Power Bi

Hi everyone, I have a column with many of its rows that were empty. Is it possible to replace the whole column with a new one? I actually wanted to fill the empty rows with random Region. (NSW, ACT, NT, SA, WA ,etc.) I was able to do it in excel - generate random text based on a list but not in Power Bi. Thanks in advance.
Here's how I did it in excel 

=CHOOSE(RANDBETWEEN(1,3),$K$4$,$K$5$,$K$6$)



ronaldbalza2023_0-1631626028468.png

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @ronaldbalza2023 

 

You can get a similar result with Power Query. First store all possible regions in a separate table. Add an index column to this table. I name the table as "Regions".

21091701.jpg

 

In original table, add an index column first. This column will not be used, but without it the random column cannot be added correctly. 

 

Then add a custom column using Int16.From(Number.RandomBetween(0, List.Max(Regions[Index]))). I name this column as RandomRegionIndex. This column has random numbers. 

 

At last, merge Regions table to this table. Select RandomRegionIndex column in this table and Index column in Regions table to match. After merging, expand the table column and select only Region column to add to this table.

21091703.jpg

21091702.jpg

 

Reference: Random Number Generation in Power BI | Sandeep Pawar (pawarbi.github.io)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @ronaldbalza2023 

 

You can get a similar result with Power Query. First store all possible regions in a separate table. Add an index column to this table. I name the table as "Regions".

21091701.jpg

 

In original table, add an index column first. This column will not be used, but without it the random column cannot be added correctly. 

 

Then add a custom column using Int16.From(Number.RandomBetween(0, List.Max(Regions[Index]))). I name this column as RandomRegionIndex. This column has random numbers. 

 

At last, merge Regions table to this table. Select RandomRegionIndex column in this table and Index column in Regions table to match. After merging, expand the table column and select only Region column to add to this table.

21091703.jpg

21091702.jpg

 

Reference: Random Number Generation in Power BI | Sandeep Pawar (pawarbi.github.io)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.