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
619SK
Helper II
Helper II

Power BI Conditional Base filter calculation

Im not able to find the neasur to calculate below condition in measure , i have updated sample

Final expected data to be on bi

619SK_0-1703152832331.png619SK_1-1703152881201.png

 

1 ACCEPTED SOLUTION

  • It's because of the order in which they are listed. 66 is greater than 30 so a match is found and no further rules will be evaluated for that value.  They should be evaluated in descending order.

= if [Age_c] ="0-15" and [Count] >=50 then 90 else if [Age_c] = "0-15" and [Count] >= 30 then 95 else 100

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

View solution in original post

4 REPLIES 4
jennratten
Super User
Super User

@619SK Please review the solution posted and click Accept as Solution if it answered your question.  Thanks!

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

619SK
Helper II
Helper II

Thanks for query

Suppose my count result is 0-15 =66

my query is  = if [Age_c] ="0-15" and [Count] >=30 then 95, if [Age_c] = "0-15" and [Count] =>50 then 90 else 100

 

Here ideally expected result for 66 count is 90 but i'm getting result of 95 point.

I'm getting first query as result.

  • It's because of the order in which they are listed. 66 is greater than 30 so a match is found and no further rules will be evaluated for that value.  They should be evaluated in descending order.

= if [Age_c] ="0-15" and [Count] >=50 then 90 else if [Age_c] = "0-15" and [Count] >= 30 then 95 else 100

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

jennratten
Super User
Super User

Hello - this is how you can accomplish it in Power Query.  Note, there are a couple of gaps in your conditions - an upper limit of defects is missing for conditions 2 and 3 and a condition is missing for the 15-30 age category.  In the solution provided, I have included the result of these as 50%.  Please change that value to whatever it should be for your requirement.  For the 15-30 category, the conditions just need to be added in the same manner.

jennratten_0-1703157196188.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRW0lEyMgASBrqGpkDKvyA1TylWByhjAuRZGAIJMwNdSwMUKZBCU5CQsYGuGaqUGZBnaAkiTHWNQVLOOfnFqRA5czxyFnjkLHFaB3Y5DimQ0zE8FgsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Defect ID" = _t, Age = _t, #"Age Category" = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Defect ID", Int64.Type}, {"Age", Int64.Type}, {"Age Category", type text}}),
    #"Inserted Text After Delimiter" = Table.AddColumn(#"Changed Type", "Age Category Max", each Number.FromText ( Text.AfterDelimiter([Age Category], "-") ), Int64.Type),
    #"Grouped Rows" = Table.Group(#"Inserted Text After Delimiter", {"Age Category", "Age Category Max"}, {{"Total Defects", each List.Count([Defect ID]), type nullable number}, {"Open Defects", each List.Count ( List.Select ( [Status], each _ = "Open" ) ), type nullable number},{"Data", each _, type table [Defect ID=nullable number, Age=nullable number, Age Category=nullable text]}}),
    #"Added Custom" = Table.AddColumn(
        #"Grouped Rows", "Points", each 
            if [Total Defects] = 0 then 100
            else if [Age Category] = "0-15" and [Open Defects] >= 30 then 80 
            else if [Age Category] = "0-15" then 100
            else if [Age Category] = "30-60" and [Total Defects] >= 40 then 50 
            else if [Age Category] = "30-60" and [Total Defects] >= 30 then 80 
            else if [Age Category] = "30-60" and [Total Defects] >= 20 then 90 
            else if [Age Category] = "30-60" then 100 
            else if [Age Category Max] >= 90 and [Total Defects] >= 45 then 50
            else if [Age Category Max] >= 90 and [Total Defects] >= 40 then 80
            else if [Age Category Max] >= 90 and [Total Defects] >= 30 then 90
            else if [Age Category Max] >= 90 then 100
            else null, type nullable number )
in
    #"Added Custom"

Based on the sample data provided, the only results are either 100 or null.  Please apply this to your full data table and let me know if the result is not as expected.  I will also be glad to help add the additional criteria to accommodate the gaps if you will provide the necessary info. 

 

 

If this post helps to answer your questions, please consider marking it as a solution so others can find it more quickly when faced with a similar challenge.

Proud to be a Microsoft Fabric Super User

Helpful resources

Announcements
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.

June 2025 community update carousel

Fabric Community Update - June 2025

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