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

For Each/Exists type of calculation in DAX

Hi,

 

Input table

Feature IDTitle FlagWorkshop Status Output
RFID0013011
RFID0013011
RFID0013011
RFID0012011
RFID0012021
RFID0012031
RFID0022040
RFID0022050
RFID0022060
RFID0032020
RFID0032040
RFID0032050

 

Above is my example table. Here I want to see if for each Feature ID if there exists Title Flag 202 and 203 both, then I want my Workshop Status = 1. If there exists only 1 out of the 2 titles 202 and 203, my Workshop STatus would still be 0(See RFID003)

 

How can i implement this in Power BI.

I prefer this solution in M Code, but I know it gets messy there. In that case DAX is also fine.

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

Hi @Anonymous ,

 

Please follow these steps:

1.Duplicate table-->Group and Combine values:

2.15.1.1.PNG

2. Add a custom column:

2.15.1.2.PNG

3. Merge these two tables:
2.15.1.3.gif

 

Or use the following formula in DAX to create a new column:

Column =
VAR _all =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Feature ID] = EARLIER ( 'Table'[Feature ID] ) ),
        [Title Flag]
    )
RETURN
    IF ( 202 IN _all && 203 IN _all, 1, 0 )

 

The final output is shown below:

2.15.1.4.PNG

 

Please take a look at the pbix file here.

 

Best Regards,
Eyelyn Qin
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

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please follow these steps:

1.Duplicate table-->Group and Combine values:

2.15.1.1.PNG

2. Add a custom column:

2.15.1.2.PNG

3. Merge these two tables:
2.15.1.3.gif

 

Or use the following formula in DAX to create a new column:

Column =
VAR _all =
    SUMMARIZE (
        FILTER ( 'Table', 'Table'[Feature ID] = EARLIER ( 'Table'[Feature ID] ) ),
        [Title Flag]
    )
RETURN
    IF ( 202 IN _all && 203 IN _all, 1, 0 )

 

The final output is shown below:

2.15.1.4.PNG

 

Please take a look at the pbix file here.

 

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

lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCnLzdDEwMFTSUTIGk4ZKsTrkihrhEDXCKmqMJmoEFjUBkgYYoqZYRc3QRI3htmGKoptrjGxuLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Feature ID" = _t, #"Title Flag" = _t, #"Workshop Status Output" = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Feature ID"}, {{"titles", each _, type table [Feature ID=nullable text, Title Flag=nullable text, Workshop Status Output=nullable text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Status", each if Table.Contains([titles],[#"Title Flag"="202"]) and Table.Contains([titles],[#"Title Flag"="203"]) then 1 else 0),
    #"Expanded titles" = Table.ExpandTableColumn(#"Added Custom", "titles", {"Title Flag"}, {"Title Flag"})
in
    #"Expanded titles"

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.