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
Anonymous
Not applicable

Create New Table With Condition

Hello Power BI heroes,

 

I have a table which contains a log for cases, every case has a unique ID and belongs to a city. Every case has one more or statuses. I want to create a summarized table which contains the case number and whether it's resolved or not.

The case is considered solved when one of these conditions is met. The conditions are:

Type: X23: statuses: T32 and T09

Type: X10, statuses: T12 and T30

Type: X1, statuses: T42 and T30

 

 

Table I have:

 

IDTypeStatus
1X23T32
1X23T09
1X32T11
2X1T12
2X1T30
3X23T11
3X23T30
3X90T01
4X53T90

 

 

Since both cases 1 and 2 met the conditions, they are considered solved!! And therefore the desired table I want to have would look like this:

 

newTable

IDResolved
1True
2True
3False
4

False

 

 

Any help would be useful! 🙂

 

Thanks!

1 ACCEPTED SOLUTION
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

Please have a try.

Manage the two tables relationship.

11.PNG

Create a measure.

Measure 2 = IF(SELECTEDVALUE('ID'[Status]) in VALUES('Table'[Status]),"Ture","False")

22.PNG

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-rongtiep-msft
Community Support
Community Support

Hi @Anonymous ,

Please have a try.

Manage the two tables relationship.

11.PNG

Create a measure.

Measure 2 = IF(SELECTEDVALUE('ID'[Status]) in VALUES('Table'[Status]),"Ture","False")

22.PNG

Best Regards

Community Support Team _ Polly

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks a lot! That works out well.

Ashish_Mathur
Super User
Super User

Hi,

Why is the resolution status of ID2 TRUE?  Please clarify.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi Ashish,

 

Thank you for your response. ID2 is resolved becasue the second entry 

2X1

T30

 has met one of the conditions. 

 

Regards, Ziad

lbendlin
Super User
Super User

Type: X23: statuses: T32 and T09

 

When you say "and"  do you mean "or" ?  Meaning the ID is True when any one condition is true?

 

First, create a reference table "Valids"  that lists the "good" conditions

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WijAyVtJRCjE2UorVgfMMLCE8QwMQz9AImWdsAOWBOCZGSByQTCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Type = _t, Status = _t])
in
    Source

 

Then apply these transforms:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYowMgaSIcZGSrE6KCIGlggRoCxQxNAQLAJiRxiCBYzQBIwNwALGCFOgepBEkNVYGoBtgqgxAYmYgtUAxWNjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Type = _t, Status = _t]),
    #"Merged Queries" = Table.NestedJoin(Source, {"Type", "Status"}, Valids, {"Type", "Status"}, "Valids", JoinKind.LeftOuter),
    #"Replaced Value" = Table.ReplaceValue(#"Merged Queries",each [Valids],each Table.RowCount([Valids]),Replacer.ReplaceValue,{"Valids"}),
    #"Grouped Rows" = Table.Group(#"Replaced Value", {"ID"}, {{"Resolved", each List.Max([Valids]), type number}})
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".

Anonymous
Not applicable

Thank you for your response and help 🙂 I actually meant "or". I will try your solution too. Thanks again.

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.