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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
bvilten
Helper III
Helper III

DAX, M, maybe R? help please

Hello All,

I posted a similar question but was not able to explaine the issue clearly enough so I am starting fresh. I thought perhaps describing the problem in terms of the VBA solution might work.

 

In VBA I read through a table to get a list of unique UserID, Then one unique UserID at a time I search through the table and put all records into a collection then I run the following if statements with the intent that only one record per loop through the collection is copied to a new sheet. I seems like I can do this with nested if statements but I can not make it work.

 

'Add resource as Active
For i = 1 To RngCount
    If Sheet2.Cells(i, 3).Offset(0, 0).Value >= Date Then
        LastRowUsed = Sheets("Active Resource Report").Range("A" & Rows.Count).End(xlUp).Row + 1
        Sheet2.Range("A" & i).EntireRow.Copy Sheets("Active Resource Report").Range("A" & LastRowUsed)
        Exit Sub
    End If
Next i

'Discard resource as properly offboarded
For i = 1 To RngCount
'Debug.Print Sheet2.Cells(i, 3).Offset(0, 0).Value
    If Sheet2.Cells(i, 3).Offset(0, 0).Value < Date Then
        If Trim(Sheet2.Cells(i, 5).Value) = "Offboard" Or Sheet2.Cells(i, 4).Value <> AED Then Exit Sub
    End If
Next i

'Add resource as possibly not offboarded
For i = 1 To RngCount
    If Sheet2.Cells(i, 3).Offset(0, 0).Value < Date Then
        If Sheet2.Cells(i, 5).Value = "Contract Extension" Or Sheet2.Cells(i, 5).Value = "Onboard" Then
                LastRowUsed = Sheets("Expired Resource Report").Range("A" & Rows.Count).End(xlUp).Row + 1
                Sheet2.Range("A" & i).EntireRow.Copy Sheets("Expired Resource Report").Range("A" & LastRowUsed)
                Exit Sub
        End If
    End If
Next i

The last post to my previous question https://community.powerbi.com/t5/Desktop/Need-help-with-DAX-formula/td-p/668053 contains sample data before and after.

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@bvilten 

 

Please check the "M" Solution as well

Table2 in the attached file

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9C4NAEET/y9XCeJ/e1cHaLo1YGIwghChW+fmOIYF4Ss6tlrePWZi6Fv49IhMSEiqXgWv1vI3t3HErX9Mw3zvRZB9zPSuotBlyQg39NS/lkSQJDcyJOEVoYffmtX0MP54mcnCbt5FiiAoUyShL5OGTniMKCClv13Lfn635uLyo4T95cc/bvGYB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [UserID = _t, LCED = _t, ACTION = _t, EXPIRED = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"UserID", Int64.Type}, {"LCED", type date}, {"ACTION", type text}, {"EXPIRED", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"UserID"}, {{"All", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Contains([All][EXPIRED],"Expired") and List.Contains([All][ACTION],"Offboard")=false),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true))
in
    #"Filtered Rows"

 

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

@bvilten 

 

Please check the "M" Solution as well

Table2 in the attached file

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZA9C4NAEET/y9XCeJ/e1cHaLo1YGIwghChW+fmOIYF4Ss6tlrePWZi6Fv49IhMSEiqXgWv1vI3t3HErX9Mw3zvRZB9zPSuotBlyQg39NS/lkSQJDcyJOEVoYffmtX0MP54mcnCbt5FiiAoUyShL5OGTniMKCClv13Lfn635uLyo4T95cc/bvGYB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [UserID = _t, LCED = _t, ACTION = _t, EXPIRED = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"UserID", Int64.Type}, {"LCED", type date}, {"ACTION", type text}, {"EXPIRED", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"UserID"}, {{"All", each _, type table}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Contains([All][EXPIRED],"Expired") and List.Contains([All][ACTION],"Offboard")=false),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true))
in
    #"Filtered Rows"

 

Zubair_Muhammad
Community Champion
Community Champion

Hi @bvilten 

 

Try this calculated table.

From Modelling tab>>New Table

 

Please see attached file as well

 

Calculated Table =
VAR CheckExpired =
    FILTER (
        VALUES ( Table1[UserID] ),
        CALCULATE ( COUNTROWS ( Table1 ), Table1[EXPIRED] = "Expired" ) > 0
    )
VAR CheckOffboard =
    EXCEPT (
        VALUES ( Table1[UserID] ),
        FILTER (
            VALUES ( Table1[UserID] ),
            CALCULATE ( COUNTROWS ( Table1 ), Table1[ACTION] = "Offboard" ) > 0
        )
    )
RETURN
    INTERSECT ( CheckExpired, CheckOffboard )

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.