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

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

Reply
eniX
Helper III
Helper III

DAX formula problem and one general question

Following scenario:

 

I have spare part items in one table. They are of some type like "engine", "mirror" etc. There are another table "Items_Cars" where those spare parts are refered to cars, in which they can be used. 

 

1.png2.png 

 

What I want to calculate for the "Items" table now is, how many alternative parts exist for each item in the table? An item is alternative if it's of the same type and can be used in the same car.

For item "4711" I have to do following:

 

- 4711 --> cars 1,2,3

- car 1 --> 4711 (same item), 4712 (alternate item!), 4713 (alternate item!), 4714 (wront type) 

- car 2 --> 4711 (same item), 4712 (alternate item!), 4715 (wrong type)

- car 3 --> 4711 (same item), 4715 (wrong type)

- Count alternate parts: 2 (do not count 4712 twice!)

 

How can I do this with DAX?

 

And one general question: Do I have variables, which I can use in the current row context? For example "filter table Items_Cars where ItemNr = [ItemNr value of the current row in the iteration]" ?

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @eniX

 

Try this Calculated Column in ITEMS TABLE

 

What are you expected RESULTS?

 

Column =
VAR myitemType = Items[Type]
VAR myTable =
    CALCULATETABLE ( VALUES ( Items_Cars[CarNr] ) )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            DISTINCT ( Items_Cars[ItemNr] ),
            FILTER ( Items, Items[Type] = myitemType ),
            FILTER (
                VALUES ( Items_Cars ),
                CONTAINS ( myTable, Items_Cars[CarNr], Items_Cars[CarNr] )
            )
        )
    )
        - 1

1046.png

View solution in original post

2 REPLIES 2
Zubair_Muhammad
Community Champion
Community Champion

Hi @eniX

 

Try this Calculated Column in ITEMS TABLE

 

What are you expected RESULTS?

 

Column =
VAR myitemType = Items[Type]
VAR myTable =
    CALCULATETABLE ( VALUES ( Items_Cars[CarNr] ) )
RETURN
    COUNTROWS (
        CALCULATETABLE (
            DISTINCT ( Items_Cars[ItemNr] ),
            FILTER ( Items, Items[Type] = myitemType ),
            FILTER (
                VALUES ( Items_Cars ),
                CONTAINS ( myTable, Items_Cars[CarNr], Items_Cars[CarNr] )
            )
        )
    )
        - 1

1046.png

Works like a charm! Thx Smiley Very Happy

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors