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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
gianmarco
Helper IV
Helper IV

Create a column which contains a list of values based on another column

Dear All,

I have the following table:

CODEGLOBAL VALUEVALUE
1651.435,00508,00
1822.732,00130,60
2153.524,001.456,00
null2.844,00null
2593.269,002.889,31
3434.589,00590,14
null1.556,00null
3623.925,001.731,54
3792.982,0068,18
3861.574,0073,61
null3.598,00null
4154.212,0057,99
4665.729,001.159,20
5892.733,00null

 

What I need to obtain is the following:

- If CODE=null, then replace nulls with a list containing all the values in CODE except null;

- In VALUE column, replace nulls with GLOBAL VALUE divided by the number of items in that list.

 

Do you think I need to manage this in PowerQuery or shall I create a set of DAX measures?

Thank You a lot

gianmarco

1 ACCEPTED SOLUTION

Is this what you are looking for?

= Table.TransformColumns( #"Changed Type", 
{{"CODE", (x)=> if x = null then List.Select(List.Distinct( #"Changed Type"[CODE]), each _<> null) else {x}},
{"GLOBAL VALUE",(x)=> if x = null then List.Select( List.Distinct( #"Changed Type"[GLOBAL VALUE]), each _<> null) else {x}},
{"VALUE",(x)=> if x = null then List.Select( List.Distinct(#"Changed Type"[VALUE]), each _<> null) else {x}}}
)

 

View solution in original post

10 REPLIES 10
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

https://1drv.ms/u/s!AiUZ0Ws7G26RijBEuIB6XELVZNMb?e=AOStoX

Dear @Ahmedx, that is close to the solution, thanks!
Once I created the lists in CODE column instead of the null values, how can I expand those lists to rows?

try this

=  Table.TransformColumns( #"Changed Type", 
{{"CODE", (x)=> if x = null then  List.Select( #"Changed Type"[CODE], each _<> null) else {x}},
{"GLOBAL VALUE",(x)=> if x = null then List.Select( #"Changed Type"[GLOBAL VALUE], each _<> null) else {x}},
{"VALUE",(x)=> if x = null then List.Select( #"Changed Type"[VALUE], each _<> null) else {x}}}
)

Dear @Ahmedx , Now I can expand list items in rows. That's fine!


Another question: If a code repeat itself in rows, the list will absorb the duplicates.
What I want is the lists to contain only unique values. I tried List.Distinct instead of List.Select but it won't work... any clues?

what do you mean where these duplicates show

In CODE column a code can show up multiple times but I need the list to show only unique values.

show the expected result for this table

CODEGLOBAL VALUEVALUE
1651.435,00508,00
1822.732,00130,60
2153.524,001.456,00
null2.844,00null
2593.269,002.889,31
3434.589,00590,14
null1.556,00null
3623.925,001.731,54
3792.982,0068,18
3861.574,0073,61
null3.598,00null
4154.212,0057,99
4665.729,001.159,20
5892.733,00null

 

Dear @Ahmedx, consider instead the following table:

 

CODEGLOBAL VALUEVALUE
1651.435,00508,00
1651.900,00600,00
1822.732,00130,60
2153.524,001.456,00
2154.000,00200,00
null2.844,00null
2593.269,002.889,31
3434.589,00590,14
null1.556,00null
3623.925,001.731,54
3792.982,0068,18
3861.574,0073,61
null3.598,00null
4154.212,0057,99
4153.200,00600,00
4154.000,00200,00
4665.729,001.159,20
5892.733,00null

 

You can see values 165, 215 and 415 are repeated multiple times in CODE column.

What I need to obtain is where CODE=null, replace null with a list of all the unique CODE values.

Is this what you are looking for?

= Table.TransformColumns( #"Changed Type", 
{{"CODE", (x)=> if x = null then List.Select(List.Distinct( #"Changed Type"[CODE]), each _<> null) else {x}},
{"GLOBAL VALUE",(x)=> if x = null then List.Select( List.Distinct( #"Changed Type"[GLOBAL VALUE]), each _<> null) else {x}},
{"VALUE",(x)=> if x = null then List.Select( List.Distinct(#"Changed Type"[VALUE]), each _<> null) else {x}}}
)

 

That's exactly what I was looking for, thanks a lot!

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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