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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

How to get rows with one column

Hi I have below data model in my Power Bi and I would expect the transformation such that my output is something as shown below? Is it possible ? Please let me know i this can be done

Input Table:

IdD0D1D2classcolor
E001234nullnull
E001534nullnull
E001nullnullnullARed

 

Table expected after transformation so that I can do a line chart plot


IndexIdValueclasscolor
1E0012nullnull
2E0013nullnull
3E0014nullnull
4E0015nullnull
5E0013nullnull
6E0014nullnull
7E001nullAred
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @Anonymous ,

 

You can also remove all the steps of "Changed Type". Then the defaul type for all columns are text.

 

After unpivotting the columns you want, select one column and click "Ctrl + A" to make all columns selected. Then, click "Detect Data Type" to change the column types.

 

For details, please check:

detect.gif

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
YukiK
Impactful Individual
Impactful Individual

You need to unpivot D columns but need replace null with 0 so that when unpivoting, the null rows will stay. Please look at the M code below. You can copy it and paste it in advanced editor (my table is entered manually, so you might need to point to the table you're pulling data from).

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjUwMFTSUTICYmMgNgHivNKcHBgVqwNXYkpYCbIwnHIE4qDUFKXYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Id = _t, D0 = _t, D1 = _t, D2 = _t, class = _t, color = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,null,0,Replacer.ReplaceValue,{"D0"}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Replaced Value", {"Id", "class", "color"}, "Attribute", "Value"),
    #"Removed Columns" = Table.RemoveColumns(#"Unpivoted Columns",{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Removed Columns",0,null,Replacer.ReplaceValue,{"Value"}),
    #"Added Index" = Table.AddIndexColumn(#"Replaced Value1", "Index", 1, 1, Int64.Type)
in
    #"Added Index"

 

 

Here is the link to the Power BI file: https://drive.google.com/file/d/1_sbY8uneYX3TYCjh5aG6mejIpgf4KOV_/view?usp=sharing

 

 

If this helped, please select this as a solution!

 

Anonymous
Not applicable

What I did was selecting column D0 , D1 and D2 and unpivoting it and that gave me desired result in above scenario. But when I do it in my actual dataset where I have around 200 columns with 65 rows of which 64 all are of Decimal type with some null values and one metadata row with text type data. On pivoting the selected columns D0-D199 , I lost the data of my 65th row and thats because as you said above 65th row here have null values from column D1-D199. the problem is I will have value as 0 as well in my dataset which is a valid value so replacing null with 0 will corrupt the dataset. what else can I replace it with or if any other idea to do it My 65th row has values after D199 column.

Icey
Community Support
Community Support

Hi @Anonymous ,

 

You can also remove all the steps of "Changed Type". Then the defaul type for all columns are text.

 

After unpivotting the columns you want, select one column and click "Ctrl + A" to make all columns selected. Then, click "Detect Data Type" to change the column types.

 

For details, please check:

detect.gif

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Icey
Community Support
Community Support

Hi @Anonymous ,

 

Any other questions?😉

 

 

Best Regards,

Icey

YukiK
Impactful Individual
Impactful Individual

Try replacing it with some other number like 2, and replace it back to null after unpivoting. The point is that you want to be able to convert the value back to null, if that makes sense.

 

Let me know if you have any other questions!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.