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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
imadelmouden
Frequent Visitor

Count rows by filtering from two tables

I want to count rows from a tableB by feltering from tableA too, in fact the tables has a commun clomuns, PHONE and WEEK.
I want to count rows that have the same PHONE and WEEK, here is the sql script I use in oracle to do that :

select count(B.phone) from tableB B, tableA A
where B.phone = A.phone and B.week = A.week;

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @imadelmouden,

 

Please add below measure into a card visual.

Measure=
VAR temptable =
    FILTER (
        CROSSJOIN (
            TableA,
            SELECTCOLUMNS ( TableB, "Week2", TableB[Week], "Phone2", TableB[Phone] )
        ),
        [Week] = [Week2]
            && [Phone] = [Phone2]
    )
RETURN
    COUNTX ( temptable, [Phone2] )

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
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

5 REPLIES 5
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @imadelmouden,

 

Please add below measure into a card visual.

Measure=
VAR temptable =
    FILTER (
        CROSSJOIN (
            TableA,
            SELECTCOLUMNS ( TableB, "Week2", TableB[Week], "Phone2", TableB[Phone] )
        ),
        [Week] = [Week2]
            && [Phone] = [Phone2]
    )
RETURN
    COUNTX ( temptable, [Phone2] )

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

i have three tables one is fact and two dimension.

 

i want distinctcount(table1[id]) by filtering table2[effective date] with user selected date range.

could you please suggest me dax for this.

Anonymous
Not applicable

Hi @imadelmouden

 

I assume that you have set up the requied relaionship between Table A and Table B.

 

Try this measure.

Measure = CALCULATE( COUNT(TableB[Phone]),
                            TableB[Phone]= TableA[Phone],
                            TableB[Week] = TableA[Week]
                            )

Thanks

 

Raj

@Anonymous when I did what you proposed, I got this error :
error.PNG

 

I have set a relationship between the two tables by PHONE number, and not the ID, because in the tableB you can find the same phone number in different rows by different week

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors