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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Elichka
Resolver I
Resolver I

Measure for query using IN statement

Hello, I need to write a measure to do the following query. 

SELECT count(*)
FROM table 1 a
WHERE a.code IN
(select b.code from table 2 b where b.id = selectedvalue(table3[id])

 

Appreciate any help/suggestions, Thank you!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Elichka 

 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards

Zhengdong Xu
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
aduguid
Super User
Super User

Try this measure out 

SelectedCount = 
VAR SelectedID = SELECTEDVALUE(Table3[id])
VAR FilteredCodes = 
    CALCULATETABLE(
        VALUES(Table2[code]),
        Table2[id] = SelectedID
    )
RETURN
    CALCULATE(
        COUNTROWS(Table1),
        Table1[code] IN FilteredCodes
    )

 

Thanks for a quick respond! When tried your solution it took loong time and got a message "Couldn't load the data for this visual". Table1 has more than 10 mln records and I have filters for visuals on the page. May be I need to add filters to the measure also? If you can add to your solution for table1 source_id = 1 and service_id = 2 ? Many thanks! 

I tried to refactor the DAX 

SelectedCount = 
VAR SelectedID = SELECTEDVALUE(Table3[id])
RETURN
    CALCULATE(
        COUNTROWS(Table1),
        FILTER(
            Table1,
            Table1[code] IN 
            CALCULATETABLE(
                VALUES(Table2[code]),
                Table2[id] = SelectedID
            )
        )
    )

Thanks! I tried refactor measure and got nothing unfortunately...

Anonymous
Not applicable

Hi @Elichka 

 

Have you solved your problem? If so, can you share your solution here and mark the correct answer as a standard answer to help other members find it faster? Thank you very much for your kind cooperation!

 

Best Regards

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

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.