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
Polly
Helper I
Helper I

Aggregating data within an IF statement Power Query

Hi,

 

I wonder if anyone can help. 

 

I am trying to construct a new column. I want it to do:

 

IF the status is complete     AND the BH_c is null     then take the median of all the BH's and put it in here

 

ELSE just use BH_c

 

I am trying this using the following M code

 

if List.AllTrue(
{ [Status]="Completed", [BH__c]=null }
) then List.Median({[BH__c]})
else [BH__c]

 

It is valid but where the status is complete     AND the BH is null it displays NULL I think this is becuase it is just looking at the row in question and the median of null is null.

 

Has anyone got any idea on how to get this to work?

 

Thanks!

1 ACCEPTED SOLUTION
MarcelBeug
Community Champion
Community Champion

Within the List.Median function, you should have <PreviousStep>[BH_1] instead of {[BH_1]}

Specializing in Power Query Formula Language (M)

View solution in original post

2 REPLIES 2
MarcelBeug
Community Champion
Community Champion

Within the List.Median function, you should have <PreviousStep>[BH_1] instead of {[BH_1]}

Specializing in Power Query Formula Language (M)

Thanks @MarcelBeug

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.