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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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
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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors