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
Arnaudd
New Member

Conditional column based on data from different rows and same user

Hello ,

I have the date as in the below power BI table,

Arnaudd_0-1724608878271.png

I want to  modify column [PassY/N] or create a new conditional column, based on the below cretaia:

if there are two rows rows for the User (ex user A) ,and in one row the column pass(Y/N) ,there is Yes, and in the other row there is No, so in the new column the value is Yes.,  so the output appears as below:

 

Arnaudd_1-1724609685244.png

thanks

1 ACCEPTED SOLUTION
LeandroDeodato
Resolver II
Resolver II

You can use the @lbendlin solution, or, if you prefer in dax, can use this mensure.

LeandroDeodato_0-1724615171160.png

 

best regards.

 

 

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1724640578869.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
LeandroDeodato
Resolver II
Resolver II

You can use the @lbendlin solution, or, if you prefer in dax, can use this mensure.

LeandroDeodato_0-1724615171160.png

 

best regards.

 

 

Thanks @lbendlin 

 

Thanks @LeandroDeodato , the DAX might be easier to implement, I tested it and it works!

but, if I have anather coloumn (ex: number of test 2), and want to do the same aggregation as the one I have done to  : "number of test" , what is the correct DAX fonction to use ?

I added an extra line (Pass2) of the other coloumn but I am getting error : The syntax for '"Pass 2"' is incorrect. 

 

New_Table = SUMMARIZE('exam (Questions)',
'exam (Questions)'[username],
"Number of Tests", COUNT('exam (Questions)'[ID]),
"Pass", if(CONTAINS('exam (Questions)','exam (Questions)'[Pass(Y/N)],"Yes"),"Yes","No")
"Pass2", if(CONTAINS('exam (Questions)','exam (Questions)'[Pass(Y/N)2],"Yes"),"Yes","No")

)

 

Thanks

 

 

There's only 1 comma missing between "Pass" and "Pass2" lines, which causes a syntax issue.

 

It should be like this:

New_Table = SUMMARIZE('exam (Questions)',
'exam (Questions)'[username],
"Number of Tests", COUNT('exam (Questions)'[ID]),
"Pass", if(CONTAINS('exam (Questions)','exam (Questions)'[Pass(Y/N)],"Yes"),"Yes","No"),
"Pass2", if(CONTAINS('exam (Questions)','exam (Questions)'[Pass(Y/N)2],"Yes"),"Yes","No")
)

 

Best Regards,
Muhammad Yousaf

 

LinkedIn

lbendlin
Super User
Super User

Group your data by user.  Add one aggregation for "Count of rows"  and another aggregation for "Maximum of [pass(Y/N)]"

 

lbendlin_0-1724613618180.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTIEYr98pVidaCUnVK4zlBuZWgzmO6LxQcqNkPguSNpjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [user = _t, #"number of test" = _t, #"pass(Y/N)" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"number of test", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"user"}, {{"Total number of test", each Table.RowCount(_), Int64.Type}, {"pass(Y/N)", each List.Max([#"pass(Y/N)"]), type nullable text}})
in
    #"Grouped Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.