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
UsePowerBI
Post Prodigy
Post Prodigy

Can you loop with PowerBI?

Hello!

 

I have the following data:

 

 Yes/NoIDSYSTEM
ABCY123A
ABCN123A
ABCY123A
ABCY123B

 

I want to loop through all the SYSTEM=A instances and compare the Yes/No indicator with the SYSTEM=B instance.

 

I then want to count the rows where the is a Yes/No mismatch between SYSTEM A and B.

 

How can I do that?

 

Can PowerBI do looping?

 

Thanks!

1 ACCEPTED SOLUTION

Hi,

 

Please take following steps:

1)Create a slicer table as below by Enter Data:

3.PNG

2)Try this measure:

Measure = 
VAR a =
    CALCULATE ( MAX ( 'Table'[Yes/No] ), FILTER ( 'Table', 'Table'[SYSTEM] = "B" ) )
VAR b =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[SYSTEM] IN FILTERS ( 'Table'[SYSTEM] )
                && 'Table'[Yes/No] = a
                && 'Table'[SYSTEM] = "A"
        )
    )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[SYSTEM] IN FILTERS ( 'Table'[SYSTEM] )
                && 'Table'[Yes/No] <> a
                && 'Table'[SYSTEM] = "A"
        )
    )
RETURN
    SWITCH ( SELECTEDVALUE ( 'Table 2'[Slicer] ), "Matches", b, "Dismatches", c )

3)The result shows:

5.PNG

See my attached pbix file.

 

Best Regards,

Giotto

View solution in original post

5 REPLIES 5
mahoneypat
Employee
Employee

You can iterate through virtual tables with DAX, so what you are asking can be done.  Another approach would be to create two virtual tables for all A and B subtables and compare then with EXCEPT, INTERSECT, etc.  For example -

 

Mismatches =
VAR Atable =
FILTER (
SUMMARIZE ( Table, Table[System], Table[ID], Table[Yes/No] ),
Table[System] = "A"
)
VAR Btable =
FILTER (
SUMMARIZE ( Table, Table[System], Table[ID], Table[Yes/No] ),
Table[System] = "B"
)
RETURN
COUNTROWS ( EXCEPT ( Atable, Btable ) )

 

If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thanks all.

 

The output should be:

Matches: 2

Mismatches: 1

 

The match/mismatch is the Y/N indicator between all the System A records comparing to the System B record.

Hi,

 

Please take following steps:

1)Create a slicer table as below by Enter Data:

3.PNG

2)Try this measure:

Measure = 
VAR a =
    CALCULATE ( MAX ( 'Table'[Yes/No] ), FILTER ( 'Table', 'Table'[SYSTEM] = "B" ) )
VAR b =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[SYSTEM] IN FILTERS ( 'Table'[SYSTEM] )
                && 'Table'[Yes/No] = a
                && 'Table'[SYSTEM] = "A"
        )
    )
VAR c =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[SYSTEM] IN FILTERS ( 'Table'[SYSTEM] )
                && 'Table'[Yes/No] <> a
                && 'Table'[SYSTEM] = "A"
        )
    )
RETURN
    SWITCH ( SELECTEDVALUE ( 'Table 2'[Slicer] ), "Matches", b, "Dismatches", c )

3)The result shows:

5.PNG

See my attached pbix file.

 

Best Regards,

Giotto

amitchandak
Super User
Super User

@UsePowerBI , earlier can help you in that. But I do not see any uniqueness to compare

https://www.red-gate.com/simple-talk/sql/bi/cracking-dax-the-earlier-and-rankx-functions/

az38
Community Champion
Community Champion

@UsePowerBI 

it's unclear, what is your desired result based on your dummy data?


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.