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

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

Reply
lazarus1907
Helper I
Helper I

Handling tables in memory

Hi,

 

I am trying to get a new column for a table counting how many times each value appears on another table. Please see diagram below:

Summarize 2.png

With normal tables, this is relatively easy, eg.

Expected result =
   ADDCOLUMNS(
      table1,
      "found", 
      CALCULATE(
         COUNTROWS(table2),
         FILTER(table2, table1[Value] = table2[Value])
      )
   )
The problem is that I've written a rather large and complicated code that relies on this same operation, but where both tables are actually variables (e.g. table1 = {1,2,3,4,5,6,7,8,9}) instead of normal tables, and of couse, you can't do table1[Value] in these cases. I've tried countless approaches, and I can't get it to work.
Any ideas?
Thanks in advance.

1 ACCEPTED SOLUTION

@lazarus1907 

You can acheive the expected result by creating the following table:

MyTable = 
VAR Tab1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
VAR Tab2 = { 4, 5, 7 }
RETURN
    ADDCOLUMNS (
        Tab1,
        "Found",
            VAR C1 = [Value]
            RETURN
                CALCULATE ( COUNTROWS ( FILTER ( Tab2, [Value] = C1 ) ) ) + 0
    )

Fowmy_0-1610709165920.png

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

5 REPLIES 5
Fowmy
Super User
Super User

@lazarus1907 

Create the table as follows:

 ADDCOLUMNS(
      table1,
      "found", 
      var c1 =  table1[Value]  return
      CALCULATE(
         COUNTROWS(table2),
         table2[Value] = c1
      )
)

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you for the reply, but Power BI does not accept table1[value] when table1 is a variable and not a normal table. That's the problem I had.

Not the solution.png

@lazarus1907 

You can acheive the expected result by creating the following table:

MyTable = 
VAR Tab1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }
VAR Tab2 = { 4, 5, 7 }
RETURN
    ADDCOLUMNS (
        Tab1,
        "Found",
            VAR C1 = [Value]
            RETURN
                CALCULATE ( COUNTROWS ( FILTER ( Tab2, [Value] = C1 ) ) ) + 0
    )

Fowmy_0-1610709165920.png

________________________

If my answer was helpful, please click Accept it as the solution to help other members find it useful

Click on the Thumbs-Up icon if you like this reply 🙂


Website YouTube  LinkedIn

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Genius! Thank you very much!!!
I'd swear I've tried something very very similar to what you wrote, but I obviously did something wrong -probably when to filter.

@lazarus1907 , That ia an array, You have create table like

 

union(

ROW("Value", 1),
ROW("Value", 2),
ROW("Value", 3)
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.